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

version 1.484.2.72.2.2, 2017/09/15 23:15:55 version 1.484.2.89, 2020/09/02 02:09:17
Line 622  sub recurse_html { Line 622  sub recurse_html {
 }  }
   
 sub group_import {  sub group_import {
     my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;      my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
     my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,      my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
         %removeparam,$importuploaded,$fixuperrors);          %removeparam,$importuploaded,$fixuperrors);
     $allmaps = {};      $allmaps = {};
Line 651  sub group_import { Line 651  sub group_import {
             }              }
         }          }
  if ($url) {   if ($url) {
             if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {  
                 $url = $1;  
                 my $marker = $2;  
                 my $info = $3;  
                 my ($toolid,%toolhash,%toolsettings);  
                 my @extras = ('linktext','explanation','crslabel','crstitle');   
                 my @toolinfo = split(/:/,$info);  
                 if ($residx) {  
                     %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);  
                     $toolid = $toolsettings{'id'};  
                 } else {  
                     $toolid = shift(@toolinfo);  
                 }  
                 $toolid =~ s/\D//g;  
                 ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},  
                  $toolhash{'linktext'},$toolhash{'explanation'},  
                  $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;  
                 foreach my $item (@extras) {  
                     $toolhash{$item} = &unescape($toolhash{$item});  
                 }  
                 if (ref($ltitoolsref) eq 'HASH') {  
                     my @deleted;  
                     if (ref($ltitoolsref->{$toolid}) eq 'HASH') {  
                         $toolhash{'id'} = $toolid;  
                         if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||  
                             ($toolhash{'target'} eq 'window')) {  
                             if ($toolhash{'target'} eq 'window') {  
                                 foreach my $item ('width','height') {  
                                     $toolhash{$item} =~ s/^\s+//;  
                                     $toolhash{$item} =~ s/\s+$//;  
                                     if ($toolhash{$item} =~ /\D/) {  
                                         delete($toolhash{$item});  
                                         if ($residx) {  
                                             if ($toolsettings{$item}) {  
                                                 push(@deleted,$item);  
                                             }  
                                         }  
                                     }  
                                 }  
                             }  
                         } elsif ($residx) {  
                             $toolhash{'target'} = $toolsettings{'target'};  
                             if ($toolhash{'target'} eq 'window') {  
                                 foreach my $item ('width','height') {  
                                     $toolhash{$item} = $toolsettings{$item};  
                                 }  
                             }  
                         } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {  
                             $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};  
                             if ($toolhash{'target'} eq 'window') {  
                                 $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};  
                                 $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};  
                             }  
                         }  
                         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') {  
                             foreach my $item ('width','height') {  
                                 delete($toolhash{$item});  
                                 if ($residx) {  
                                     if ($toolsettings{$item}) {  
                                         push(@deleted,$item);  
                                     }  
                                 }  
                             }  
                         }  
                         if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {  
                             foreach my $item ('label','title','linktext','explanation') {  
                                 my $crsitem;  
                                 if (($item eq 'label') || ($item eq 'title')) {  
                                     $crsitem = 'crs'.$item;  
                                 } else {  
                                     $crsitem = $item;  
                                 }  
                                 if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {  
                                     $toolhash{$crsitem} =~ s/^\s+//;  
                                     $toolhash{$crsitem} =~ s/\s+$//;  
                                     if ($toolhash{$crsitem} eq '') {  
                                         delete($toolhash{$crsitem});  
                                     }  
                                 } else {  
                                     delete($toolhash{$crsitem});  
                                 }  
                                 if (($residx) && (exists($toolsettings{$crsitem}))) {  
                                     unless (exists($toolhash{$crsitem})) {  
                                         push(@deleted,$crsitem);  
                                     }  
                                 }  
                             }  
                         }  
                         my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);  
                         if ($putres eq 'ok') {  
                             if (@deleted) {  
                                 &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);  
                             }  
                         }  
                     }  
                 }  
             }  
             if (($caller eq 'londocs') &&              if (($caller eq 'londocs') &&
                 ($folder =~ /^default/)) {                  ($folder =~ /^default/)) {
                 if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {                  if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
Line 768  sub group_import { Line 662  sub group_import {
                     $donechk = 1;                      $donechk = 1;
                 }                  }
                 if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {                  if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
                     &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,                      &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
                                          \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);                                           \%addedmaps,\%hierarchy,\%titles,$allmaps);
                     $importuploaded = 1;                      $importuploaded = 1;
                 } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {                  } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
                     next if ($allmaps->{$url});                      next if ($allmaps->{$url});
Line 940  sub docs_change_log { Line 834  sub docs_change_log {
              '// <![CDATA['."\n".               '// <![CDATA['."\n".
              &Apache::loncommon::display_filter_js('docslog')."\n".               &Apache::loncommon::display_filter_js('docslog')."\n".
              &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,               &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
                          $coursedom,$coursenum,'',$canedit,\$navmap)."\n".                           $coursedom,$coursenum,$canedit,'',\$navmap)."\n".
              &history_tab_js()."\n".               &history_tab_js()."\n".
              &Apache::lonratedt::editscript('simple')."\n".               &Apache::lonratedt::editscript('simple')."\n".
              '// ]]>'."\n".               '// ]]>'."\n".
Line 1165  sub update_paste_buffer { Line 1059  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 1118  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 1214  sub update_paste_buffer { Line 1126  sub update_paste_buffer {
                 $subdir = $prefix;                  $subdir = $prefix;
             }              }
             my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);              my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
             &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,              &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
                                  \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);                                   \%hierarchy,\%titles,\%allmaps);
             if (ref($hierarchy{$url}) eq 'HASH') {              if (ref($hierarchy{$url}) eq 'HASH') {
                 my ($nested,$nestednames);                  my ($nested,$nestednames);
                 &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);                  &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
Line 1284  sub print_paste_buffer { Line 1196  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);
             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$}) {  
                 $is_exttool = 1;  
             }              }
             if ($folder =~ /^supplemental/) {              if ($folder =~ /^supplemental/) {
                 $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});                  $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
Line 1326  sub print_paste_buffer { Line 1237  sub print_paste_buffer {
                         $is_uploaded_map = 1;                          $is_uploaded_map = 1;
                     }                      }
                 } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||                  } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
                          ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {                           ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
                     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)) {                              $othercrs = '<br />'.&mt('(from another course)');
                                 $canpaste = 0;  
                                 $nopaste = &mt('Paste from another domain unavailable.');  
                             } else {  
                                 $othercrs = '<br />'.&mt('(from another course)');  
                             }  
                         } else {                          } else {
                             $canpaste = 0;                              $canpaste = 0;
                             $nopaste = &mt('Paste from another course unavailable.');                              $nopaste = &mt('Paste from another course unavailable.');
                         }                          }
                     }                      }
                 }                  }
             }                  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).')';
             } elsif ($is_exttool) {  
                 $buffer = &mt('External Tool').': '.  
                     &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});  
             } else {              } else {
                 my $icon = &Apache::loncommon::icon($extension);                  my $icon = &Apache::loncommon::icon($extension);
                 if ($extension eq 'sequence' &&                  if ($extension eq 'sequence' &&
Line 1409  sub print_paste_buffer { Line 1312  sub print_paste_buffer {
             }              }
             $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.('&nbsp;'x2);              $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.('&nbsp;'x2);
         }          }
         $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.('&nbsp;'x2);          $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Clear selected').'" />'.('&nbsp;'x2);
         if ($clipboardcount > 1) {          if ($clipboardcount > 1) {
             $buttons .=              $buttons .=
                 '<span style="text-decoration:line-through">'.('&nbsp;'x20).'</span>'.('&nbsp;'x2).                  '<span style="text-decoration:line-through">'.('&nbsp;'x20).'</span>'.('&nbsp;'x2).
Line 1510  sub supp_pasteable { Line 1413  sub supp_pasteable {
         (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||          (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
         ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||          ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
         ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||          ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
         ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||          ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
         ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {  
         return 1;          return 1;
     }      }
     return;      return;
Line 1633  sub do_paste_from_buffer { Line 1535  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,%duplicate,
         %prefixchg,%srcdom,%srcnum,%marktomove,$save_err,$lockerrors,$allresult);          %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
   
     foreach my $suffix (@topaste) {      foreach my $suffix (@topaste) {
         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});          my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
         my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});          my $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 1563  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)$})) {
             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 1670  sub do_paste_from_buffer { Line 1574  sub do_paste_from_buffer {
                     next;                      next;
                 }                  }
             }              }
 # When buffer was populated using an active role in a different course  
 # disallow pasting of External Tool if course is in a different domain.  
             if ($srcd ne $coursedom) {  
                 $notindom{$suffix} = 1;  
                 next;  
             }  
             $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; 
Line 1728  sub do_paste_from_buffer { Line 1627  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.',   
                 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 1655  sub do_paste_from_buffer {
 # Retrieve information about all course maps in main content area   # Retrieve information about all course maps in main content area 
   
     my $allmaps = {};      my $allmaps = {};
     if ($folder =~ /^default/) {      my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
         $allmaps =  
             &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,  
                                                  $env{"course.$env{'request.course.id'}.home"},  
                                                  $env{'request.course.id'});  
     }  
   
     my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);  
   
 # Loop over the items to paste  # Loop over the items to paste
     foreach my $suffix (@dopaste) {      foreach my $suffix (@dopaste) {
 # Maps need to be copied first  # Maps need to be copied first
         my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,          my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
             %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,              %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
             %newurls,%tomove);              %newurls,%tomove,%resdatacopy);
         if (ref($marktomove{$suffix}) eq 'ARRAY') {          if (ref($marktomove{$suffix}) eq 'ARRAY') {
             map { $tomove{$_} = 1; } @{$marktomove{$suffix}};              map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
         }          }
Line 1782  sub do_paste_from_buffer { Line 1673  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);
             &contained_map_check($url,$folder,$coursenum,$coursedom,              if (($folder =~ /^default/) && (!$donechk)) {
                                  \%removefrommap,\%removeparam,\%addedmaps,                  $allmaps =
                                  \%hierarchy,\%titles,$allmaps);                      &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
                                                            $env{"course.$env{'request.course.id'}.home"},
                                                            $env{'request.course.id'});
                   $donechk = 1; 
               }
               &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
                                    \%addedmaps,\%hierarchy,\%titles,$allmaps);
             if ($url=~ m{^/uploaded/}) {              if ($url=~ m{^/uploaded/}) {
                 my $newurl;                  my $newurl;
                 unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {                  unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
Line 1814  sub do_paste_from_buffer { Line 1711  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 1720  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 1734  sub do_paste_from_buffer {
                 }                  }
             }              }
         }          }
         if ($url=~ m{/(ext\.tool)$}) {          if ($url=~ m{/(bulletinboard|smppg)$}) {
             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 1742  sub do_paste_from_buffer {
                          src  => $url,                           src  => $url,
                          cdom => $coursedom,                           cdom => $coursedom,
                          cnum => $coursenum,                           cnum => $coursenum,
             );                         );
             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;
Line 1861  sub do_paste_from_buffer { Line 1758  sub do_paste_from_buffer {
                     $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 external tool.').' '.$errtext;                          $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;
                     }                      }
                     $results{$suffix} = $result;                      $results{$suffix} = $result;
                     $msgerrs{$suffix} = $msg;                      $msgerrs{$suffix} = $msg;
Line 1927  sub do_paste_from_buffer { Line 1826  sub do_paste_from_buffer {
                         }                          }
                     }                      }
                 }                  }
               } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   my $template = $1;
                   if ($newidx) {
                       &copy_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
                                             $coursedom,$coursenum,$template,$newidx,"$folder.$container");
                   }
             }              }
             $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).              $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                                               ':'.$ext.':normal:res';                                                ':'.$ext.':normal:res';
Line 1940  sub do_paste_from_buffer { Line 1845  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 1854  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 2114  sub dbcopy { Line 2021  sub dbcopy {
     my ($url,$result,$errtext);      my ($url,$result,$errtext);
     if (ref($dbref) eq 'HASH') {      if (ref($dbref) eq 'HASH') {
         $url = $dbref->{'src'};          $url = $dbref->{'src'};
         if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {          if ($url =~ m{/(smppg|bulletinboard)$}) {
             my $prefix = $1;              my $prefix = $1;
             if ($prefix eq 'ext.tool') {  
                 $prefix = 'exttool';  
             }  
             if (($dbref->{'cdom'} =~ /^$match_domain$/) &&              if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
                 ($dbref->{'cnum'} =~ /^$match_courseid$/)) {                  ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
                 my $db_name;                  my $db_name;
Line 2129  sub dbcopy { Line 2033  sub dbcopy {
                         &Apache::lonsimplepage::get_db_name($url,$marker,                          &Apache::lonsimplepage::get_db_name($url,$marker,
                                                             $dbref->{'cdom'},                                                              $dbref->{'cdom'},
                                                             $dbref->{'cnum'});                                                              $dbref->{'cnum'});
                 } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {  
                     $db_name = 'exttool_'.$marker;  
                 } else {                  } else {
                     $db_name = 'bulletinpage_'.$marker;                      $db_name = 'bulletinpage_'.$marker;
                 }                  }
Line 2141  sub dbcopy { Line 2043  sub dbcopy {
                 if (!$suffix) {                  if (!$suffix) {
                     if ($prefix eq 'smppg') {                      if ($prefix eq 'smppg') {
                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);                          $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
                     } elsif ($prefix eq 'exttool') {  
                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);  
                     } else {                      } else {
                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);                          $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
                     }                      }
Line 2176  sub dbcopy { Line 2076  sub dbcopy {
                     $result=&Apache::lonnet::put($db_name,\%contents,                      $result=&Apache::lonnet::put($db_name,\%contents,
                                                  $coursedom,$coursenum);                                                   $coursedom,$coursenum);
                     if ($result eq 'ok') {                      if ($result eq 'ok') {
                         $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;                          $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
                     }                      }
                 }                  }
                 if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {                  if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
Line 2186  sub dbcopy { Line 2086  sub dbcopy {
                     if ($prefix eq 'smppg') {                      if ($prefix eq 'smppg') {
                         $lockerrorsref->{$prefix} .=                          $lockerrorsref->{$prefix} .=
                             ' '.&mt('This will prevent creation of additional simple pages in this course.');                              ' '.&mt('This will prevent creation of additional simple pages in this course.');
                     } elsif ($prefix eq 'exttool') {  
                         $lockerrorsref->{$prefix} .=  
                             ' '.&mt('This will prevent addition of more external tools to this course.');  
                     } else {                      } else {
                         $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');                          $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
                     }                      }
Line 2214  sub dbcopy { Line 2111  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 2229  sub uniqueness_check { Line 2217  sub uniqueness_check {
 }  }
   
 sub contained_map_check {  sub contained_map_check {
     my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,      my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
         $hierarchy,$titles,$allmaps) = @_;          $allmaps) = @_;
     my $content = &Apache::lonnet::getfile($url);      my $content = &Apache::lonnet::getfile($url);
     unless ($content eq '-1') {      unless ($content eq '-1') {
         my $parser = HTML::TokeParser->new(\$content);          my $parser = HTML::TokeParser->new(\$content);
Line 2259  sub contained_map_check { Line 2247  sub contained_map_check {
                             $addedmaps->{$ressrc} = [$url];                              $addedmaps->{$ressrc} = [$url];
                         }                          }
                     }                      }
                     &contained_map_check($ressrc,$folder,$coursenum,$coursedom,                      &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
                                          $removefrommap,$removeparam,  
                                          $addedmaps,$hierarchy,$titles,$allmaps);                                           $addedmaps,$hierarchy,$titles,$allmaps);
                 }                  }
             } elsif ($token->[1] eq 'param') {              } elsif ($token->[1] eq 'param') {
Line 2280  sub contained_map_check { Line 2267  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 2316  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 2340  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 2382  sub url_paste_fixups { Line 2369  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 2406  sub apply_fixups {
         $oldurl,$url,$caller) = @_;          $oldurl,$url,$caller) = @_;
     my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,      my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
         %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,          %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
         %lockerrors,$lockmsg);          %resdatacopy,%lockerrors,$lockmsg);
     if (ref($updated) eq 'HASH') {      if (ref($updated) eq 'HASH') {
         if (ref($updated->{'rewrites'}) eq 'HASH') {          if (ref($updated->{'rewrites'}) eq 'HASH') {
             %rewrites = %{$updated->{'rewrites'}};              %rewrites = %{$updated->{'rewrites'}};
Line 2433  sub apply_fixups { Line 2426  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 2583  sub apply_fixups { Line 2579  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 2624  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 2635  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 2677  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 2909  sub handle_edit_cmd { Line 2936  sub handle_edit_cmd {
   
 sub editor {  sub editor {
     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,      my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
         $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,          $supplementalflag,$orderhash,$iconpath,$pathitem,$canedit,
         $canedit,$navmapref,$hiddentop)=@_;          $hostname,$navmapref,$hiddentop)=@_;
     my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);      my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
     if ($allowed) {      if ($allowed) {
         (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,          (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
Line 3121  sub editor { Line 3148  sub editor {
                         } else {                          } else {
                             return $errortxt;                              return $errortxt;
                         }                          }
                     } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {  
                         my ($suffix,$errortxt,$locknotfreed) =  
                             &new_timebased_suffix($coursedom,$coursenum,'exttool');  
                         if ($locknotfreed) {  
                             $r->print($locknotfreed);  
                         }  
                         if ($suffix) {  
                             $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};  
                         } else {  
                             return $errortxt;  
                         }  
                     } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {                      } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
                         if ($supplementalflag) {                          if ($supplementalflag) {
                             next unless ($1 eq 'supplemental');                              next unless ($1 eq 'supplemental');
Line 3154  sub editor { Line 3170  sub editor {
     }      }
             ($errtext,$fatal,my $fixuperrors) =              ($errtext,$fatal,my $fixuperrors) =
                 &group_import($coursenum, $coursedom, $folder,$container,                  &group_import($coursenum, $coursedom, $folder,$container,
                               'londocs',$ltitoolsref,@imports);                                'londocs',@imports);
     return $errtext if ($fatal);      return $errtext if ($fatal);
             if ($fixuperrors) {              if ($fixuperrors) {
                 $r->print($fixuperrors);                  $r->print($fixuperrors);
Line 3240  sub editor { Line 3256  sub editor {
         $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,$canedit,
                               $isencrypted,$navmapref);                                $isencrypted,$navmapref,$hostname);
         $idx++;          $idx++;
         $shown++;          $shown++;
     }      }
Line 3620  sub is_supplemental_title { Line 3636  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)=@_;          $canedit,$isencrypted,$navmapref,$hostname)=@_;
     my ($foldertitle,$renametitle,$oldtitle);      my ($foldertitle,$renametitle,$oldtitle);
     if (&is_supplemental_title($title)) {      if (&is_supplemental_title($title)) {
  ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);   ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
Line 3717  END Line 3733  END
  'rn' => 'Rename',   'rn' => 'Rename',
  'cp' => 'Copy',   'cp' => 'Copy',
                 'ex' => 'External Resource',                  'ex' => 'External Resource',
                 'et' => 'External Tool',  
                 'ed' => 'Edit',                  'ed' => 'Edit',
                 'pr' => 'Preview',                  'pr' => 'Preview',
                 'sv' => 'Save',                  'sv' => 'Save',
Line 3737  END Line 3752  END
     |/aboutme$      |/aboutme$
     |/navmaps$      |/navmaps$
     |/bulletinboard$      |/bulletinboard$
                             |/ext\.tool$  
     |\.html$)}x)      |\.html$)}x)
              || $isexternal) {               || $isexternal) {
     $skip_confirm = 1;      $skip_confirm = 1;
Line 3872  END Line 3886  END
     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 3912  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:/)) {
                     $nomodal = 1;                      $nomodal = 1;
                 }                  }
             } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {  
                 $url='/adm/wrapper'.$url;  
             } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {              } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
                 if (($ENV{'SERVER_PORT'} == 443) &&                  if (($ENV{'SERVER_PORT'} == 443) &&
                     ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {                      ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
                       unless (&Apache::lonnet::uses_sts()) {
                           $url .= '?usehttp=1';
                       }
                     $nomodal = 1;                      $nomodal = 1;
                 }                  }
     }      }
             if (&Apache::lonnet::symbverify($symb,$url)) {              if (&Apache::lonnet::symbverify($symb,$url)) {
                 my $shownsymb = $symb;                  my $shownsymb = $symb;
                 if ($isexternal) {                  if ($isexternal) {
                     if ($url =~ /^([^#]+)#([^#]+)$/) {                      $url =~ s/\#[^#]+$//;
                         $url = $1;                      if ($container eq 'page') {
                         $anchor = $2;                          $url = &Apache::lonnet::clutter($url);
                         if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {  
                             $shownsymb = $1.&escape('#').$anchor;  
                         }  
                     }                      }
                 }                  }
                 unless ($env{'request.role.adv'}) {                  unless ($env{'request.role.adv'}) {
Line 3925  END Line 3945  END
                     }                      }
                 }                  }
                 if ($url ne '') {                  if ($url ne '') {
                     $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');                      $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
                 }                  }
             } elsif (!$env{'request.role.adv'}) {              } elsif (!$env{'request.role.adv'}) {
                 my $checkencrypt;                  my $checkencrypt;
Line 3946  END Line 3966  END
                     my $shownsymb = &Apache::lonenc::encrypted($symb);                      my $shownsymb = &Apache::lonenc::encrypted($symb);
                     my $shownurl = &Apache::lonenc::encrypted($url);                      my $shownurl = &Apache::lonenc::encrypted($url);
                     if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {                      if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
                         $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');                          $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
                         if ($env{'request.enc'} ne '') {                          if ($env{'request.enc'} ne '') {
                             delete($env{'request.enc'});                              delete($env{'request.enc'});
                         }                          }
Line 3966  END Line 3986  END
                 $url = $1;                  $url = $1;
                 $anchor = $2;                  $anchor = $2;
                 if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {                  if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
                       unless (&Apache::lonnet::uses_sts()) {
                           if ($hostname ne '') {
                               $url = 'http://'.$hostname.$url;
                           }
                           $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
                       }
                     $nomodal = 1;                      $nomodal = 1;
                 }                  }
             }              }
         } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {          } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
             if (($ENV{'SERVER_PORT'} == 443) &&              if (($ENV{'SERVER_PORT'} == 443) &&
                 ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {                  ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
                   unless (&Apache::lonnet::uses_sts()) {
                       if ($hostname ne '') {
                           $url = 'http://'.$hostname.$url;
                       }
                       $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
                   }
                 $nomodal = 1;                  $nomodal = 1;
             }              }
         }          }
Line 4062  $form_common."\n". Line 4094  $form_common."\n".
 $form_end;  $form_end;
         }          }
     } elsif ($supplementalflag && !$allowed) {      } elsif ($supplementalflag && !$allowed) {
         my $isexttool;  
         if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {  
             $url='/adm/wrapper'.$url;  
             $isexttool = 1;  
         }  
         $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='.&HTML::Entities::encode($renametitle,'<>&"');
         }          }
         if ((($isexternal) || ($isexttool)) && $orderidx) {          if ($isexternal && $orderidx) {
             $url .= '&amp;idx='.$orderidx;              $url .= '&amp;idx='.$orderidx;
         }          }
         if ($anchor ne '') {          if ($anchor ne '') {
Line 4087  $form_end; Line 4114  $form_end;
             ($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,$disabled);
         } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {  
             ($editlink,$extresform) =  
                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,  
                                                      undef,undef,undef,'tool',$coursedom,  
                                                      $coursenum,$ltitoolsref,$disabled);  
         } elsif (!$isfolder && !$ispage) {          } elsif (!$isfolder && !$ispage) {
             my ($cfile,$home,$switchserver,$forceedit,$forceview) =               my ($cfile,$home,$switchserver,$forceedit,$forceview) = 
                 &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);                  &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
Line 4106  $form_end; Line 4128  $form_end;
                                                             $forceedit,                                                              $forceedit,
                                                             undef,$symb,                                                              undef,$symb,
                                                             &escape($env{'form.folderpath'}),                                                              &escape($env{'form.folderpath'}),
                                                             $renametitle,'','',1,$suppanchor);                                                              $renametitle,$hostname,
                                                               '','',1,$suppanchor);
                 if ($jscall) {                  if ($jscall) {
                     $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.                      $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
                                 $jscall.'" >'.&mt('Edit').'</a>&nbsp;'."\n";                                  $jscall.'" >'.&mt('Edit').'</a>&nbsp;'."\n";
Line 4134  $form_end; Line 4157  $form_end;
                $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');                 $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
            }             }
        }         }
        $link = &js_escape($url.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.  
                                                (($anchor ne '')?$anchor:''));         if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
              $link = 'http://'.$hostname.$url;
          } else {
              $link = $url;
          }
          $link = &js_escape($link.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.$anchor);
        if ($nomodal) {         if ($nomodal) {
            $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.             $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
                   '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';                    '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
Line 4215  sub action_restrictions { Line 4243  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 4294  sub new_timebased_suffix { Line 4324  sub new_timebased_suffix {
             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');              $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
         } elsif ($type eq 'smppg') {          } elsif ($type eq 'smppg') {
             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');              $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
         } elsif ($type eq 'exttool') {  
             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');  
         } else {          } else {
             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');              $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
         }          }
Line 4324  sub new_timebased_suffix { Line 4352  sub new_timebased_suffix {
         } elsif ($type eq 'smppg') {          } elsif ($type eq 'smppg') {
             $locknotfreed .=              $locknotfreed .=
                 &mt('This will prevent creation of additional simple pages in this course.');                  &mt('This will prevent creation of additional simple pages in this course.');
         } elsif ($type eq 'exttool') {  
             $locknotfreed .=  
                 &mt('This will prevent creation of additional external tools in this course.');  
         } else {          } else {
             $locknotfreed .=              $locknotfreed .=
                 &mt('This will prevent creation of additional discussion boards in this course.');                  &mt('This will prevent creation of additional discussion boards in this course.');
Line 4377  sub untiehash { Line 4402  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 4417  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 4466  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 4480  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 4535  sub list_symbs {
     $r->print(&endContentScreen());      $r->print(&endContentScreen());
 }  }
   
   sub contentverifyform {
       my ($r) = @_;
       my $crstype = &Apache::loncommon::course_type();
       $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
       $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
       $r->print(&startContentScreen('tools'));
       $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
       $r->print('<form method="post" action="/adm/coursedocs"><p>'.
                 &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
                 '&nbsp;<span class="LC_nobreak">'.
                 '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
                 &mt('No').'</label>'.('&nbsp;'x2).
                 '<label><input type="radio" name="checkstale" value="1" />'.
                 &mt('Yes').'</label></span></p><p>'.
                 '<input type="submit" value="'.&mt('Verify content').' "/>'.
                 '<input type="hidden" value="1" name="tools" />'.
                 '<input type="hidden" value="1" name="verify" /></p></form>');
       $r->print(&endContentScreen());
       return;
   }
   
 sub verifycontent {  sub verifycontent {
     my ($r) = @_;      my ($r,$checkstale) = @_;
     my $crstype = &Apache::loncommon::course_type();      my $crstype = &Apache::loncommon::course_type();
     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));      $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));      $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
Line 4518  sub verifycontent { Line 4578  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 4948  sub handler { Line 5008  sub handler {
 #  #
 # --------------------------------------------- Initialize help topics for this  # --------------------------------------------- Initialize help topics for this
     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','Navigate_Content',
                        'Navigate_Content','Adding_Folders','Docs_Overview',                 'Adding_Folders','Docs_Overview', 'Load_Map',
                'Load_Map','Supplemental','Score_Upload_Form',                 'Supplemental','Score_Upload_Form','Adding_Pages',
                        'Adding_Pages','Importing_LON-CAPA_Resource',                 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
                        'Importing_IMS_Course','Uploading_From_Harddrive',                         'Uploading_From_Harddrive','Course_Roster','Web_Page',
                        'Course_Roster','Web_Page','Dropbox','Simple_Problem') {                         'Dropbox','Simple_Problem') {
  $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);   $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
     }      }
     # Composite help files      # Composite help files
Line 4985  sub handler { Line 5045  sub handler {
         $disabled = ' disabled="disabled"';          $disabled = ' disabled="disabled"';
     }      }
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
       if ($env{'form.inhibitmenu'}) {
           unless ($env{'form.inhibitmenu'} eq 'yes') {
               delete($env{'form.inhibitmenu'});
           }
       }
   
   if ($allowed && $env{'form.verify'}) {    if ($allowed && $env{'form.verify'}) {
       &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');        &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
       &verifycontent($r);        if (!$canedit) {
             &verifycontent($r);
         } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
             &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
                                                     text=>'Results',
                                                     faq=>273,
                                                     bug=>'Instructor Interface'});
             &verifycontent($r,$env{'form.checkstale'});
         } else {
             &contentverifyform($r);
         }
   } elsif ($allowed && $env{'form.listsymbs'}) {    } elsif ($allowed && $env{'form.listsymbs'}) {
       &init_breadcrumbs('listsymbs','List Content IDs');        &init_breadcrumbs('listsymbs','List Content IDs');
       &list_symbs($r);        &list_symbs($r);
Line 5018  sub handler { Line 5094  sub handler {
                                              'forcesupplement','forcestandard',                                               'forcesupplement','forcestandard',
                                              'tools','symb','command','supppath']);                                               'tools','symb','command','supppath']);
   
       foreach my $item ('forcesupplement','forcestandard','tools') {
           next if ($env{'form.'.$item} eq '');
           unless ($env{'form.'.$item} eq '1') {
               delete($env{'form.'.$item});
           }
       }
   
       if ($env{'form.command'}) {
           unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
               delete($env{'form.command'});
           }
       }
   
       if ($env{'form.symb'}) {
           my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
           unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
               delete($env{'form.symb'});
           }
       }
   
 # standard=1: this is a "new-style" course with an uploaded map as top level  # standard=1: this is a "new-style" course with an uploaded map as top level
 # standard=2: this is a "old-style" course, and there is nothing we can do  # standard=2: this is a "old-style" course, and there is nothing we can do
   
Line 5040  sub handler { Line 5136  sub handler {
     my $toolsflag=0;      my $toolsflag=0;
     if ($env{'form.tools'}) { $toolsflag=1; }      if ($env{'form.tools'}) { $toolsflag=1; }
   
       if ($env{'form.folderpath'} ne '') {
           my @items = split(/\&/,$env{'form.folderpath'});
           my $badpath;
           for (my $i=0; $i<@items; $i++) {
               my $odd = $i%2;
               if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
                   $badpath = 1;
               } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
                   $badpath = 1;
               }
               last if ($badpath);
           }
           if ($badpath) {
               delete($env{'form.folderpath'});
           }
       }
   
       if ($env{'form.supppath'} ne '') {
           my @items = split(/\&/,$env{'form.supppath'});
           my $badpath;
           for (my $i=0; $i<@items; $i++) {
               my $odd = $i%2;
               if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
                   $badpath = 1;
               }
               last if ($badpath);
           }
           if ($badpath) {
               delete($env{'form.supppath'});
           }
       }
   
     my $script='';      my $script='';
     my $showdoc=0;      my $showdoc=0;
     my $addentries = {};      my $addentries = {};
     my $container;      my $container;
     my $containertag;      my $containertag;
     my $pathitem;      my $pathitem;
     my %ltitools;  
     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 5120  sub handler { Line 5247  sub handler {
             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';
Line 5224  sub handler { Line 5351  sub handler {
                 }                  }
             }              }
             my $tabidstr = join("','",@tabids);              my $tabidstr = join("','",@tabids);
             %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);              my $hostname = $r->hostname();
             my $posslti = keys(%ltitools);      $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,
     $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,                                     $canedit,$hostname,\$navmap).
                                    $canedit,\$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();
             $addentries = {              $addentries = {
                             onload   => "javascript:resize_scrollbox('contentscroll','1','1');",                              onload   => "javascript:resize_scrollbox('contentscroll','1','1');",
                           };                            };
Line 5247  sub handler { Line 5373  sub handler {
               .'// <![CDATA['."\n"                .'// <![CDATA['."\n"
               .$script."\n"                .$script."\n"
               .'// ]]>'."\n"                .'// ]]>'."\n"
               .'</script>'."\n";                .'</script>'."\n"
                 .'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>'."\n";
   
     # Breadcrumbs      # Breadcrumbs
     &Apache::lonhtmlcommon::clear_breadcrumbs();      &Apache::lonhtmlcommon::clear_breadcrumbs();
Line 5366  sub handler { Line 5493  sub handler {
                 'impo' => 'Import',                  'impo' => 'Import',
  'lnks' => 'Import from Stored Links',   'lnks' => 'Import from Stored Links',
                 'impm' => 'Import from Assembled Map',                  'impm' => 'Import from Assembled Map',
                 'extr' => 'External Resource',  
                 'extt' => 'External Tool',  
                 'selm' => 'Select Map',                  'selm' => 'Select Map',
                 'load' => 'Load Map',                  'load' => 'Load Map',
                 'newf' => 'New Folder',                  'newf' => 'New Folder',
Line 5399  sub handler { Line 5524  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 5559  sub handler {
  my $fileupload=(<<FIUP);   my $fileupload=(<<FIUP);
         $quotainfo          $quotainfo
  $lt{'file'}:<br />   $lt{'file'}:<br />
  <input type="file" name="uploaddoc" size="40" $disabled />   <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
           <input type="hidden" id="LC_free_space" value="$free_space" />
 FIUP  FIUP
   
  my $checkbox=(<<CHBO);   my $checkbox=(<<CHBO);
Line 5538  SEDFFORM Line 5665  SEDFFORM
             &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,$disabled);
         my $exttoolform =  
             &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,  
                                                  $help{'Adding_External_Tool'},undef,  
                                                  undef,'tool',$coursedom,$coursenum,  
                                                  \%ltitools,$disabled);  
     if ($allowed) {      if ($allowed) {
         my $folder = $env{'form.folder'};          my $folder = $env{'form.folder'};
         if ($folder eq '') {          if ($folder eq '') {
Line 5586  HIDDENFORM Line 5708  HIDDENFORM
 #  #
   
     my $savefolderpath;      my $savefolderpath;
       my $hostname = $r->hostname();
   
     if ($allowed) {      if ($allowed) {
        my $folder=$env{'form.folder'};         my $folder=$env{'form.folder'};
Line 5777  NSYLFORM Line 5900  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)) {  
             push(@importdoc,  
                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},  
         );  
         }  
         unless ($container eq 'page') {          unless ($container eq 'page') {
             push(@importdoc,              push(@importdoc,
                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
Line 5826  my %orderhash = ( Line 5950  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);                                $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 5971  unless ($container eq 'page') {
                  &mark_hash_old();                   &mark_hash_old();
              }               }
           }            }
   
           &changewarning($r,'');            &changewarning($r,'');
         }          }
     }      }
Line 5907  SNFFORM Line 6032  SNFFORM
                                                  $help{'Adding_External_Resource'},                                                   $help{'Adding_External_Resource'},
                                                  undef,undef,$disabled);                                                   undef,undef,$disabled);
   
         my $supexttoolform =  
             &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,  
                                                  $help{'Adding_External_Tool'},  
                                                  undef,undef,'tool',$coursedom,  
                                                  $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 5965  my @specialdocs = ( Line 6085  my @specialdocs = (
  );   );
 my @supimportdoc = (  my @supimportdoc = (
  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
             =>$supextform});              =>$supextform},
         if (keys(%ltitools)) {  
             push(@supimportdoc,  
                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'  
             =>$supexttoolform});  
         }  
         push(@supimportdoc,  
                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
             =>$supupdocform},              =>$supupdocform},
         );                     );
   
 $supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc));  $supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc));
 my %suporderhash = (  my %suporderhash = (
Line 5985  my %suporderhash = ( Line 6099  my %suporderhash = (
         if ($supplementalflag) {          if ($supplementalflag) {
            my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,             my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
                                $supplementalflag,\%suporderhash,$iconpath,$pathitem,                                 $supplementalflag,\%suporderhash,$iconpath,$pathitem,
                                \%ltitools,$canedit);                                 $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>');
            } else {             } else {
Line 6005  my %suporderhash = ( Line 6119  my %suporderhash = (
         }          }
     } 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,'',$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 6153  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 6174  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 6204  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 6377  END Line 6499  END
 }  }
   
 sub editing_js {  sub editing_js {
     my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$canedit,$navmapref) = @_;      my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,
           $canedit,$hostname,$navmapref) = @_;
     my %js_lt = &Apache::lonlocal::texthash(      my %js_lt = &Apache::lonlocal::texthash(
                                           p_mnf => 'Name of New Folder',                                            p_mnf => 'Name of New Folder',
                                           t_mnf => 'New Folder',                                            t_mnf => 'New Folder',
Line 6456  sub editing_js { Line 6579  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()) {
                               if ($hostname ne '') {
                                   $backtourl = 'http://'.$hostname.$backtourl;
                               }
                               $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
                           }
                       }
                   } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
                       if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
                           unless (&Apache::lonnet::uses_sts()) {
                               if ($hostname ne '') {
                                   $backtourl = 'http://'.$hostname.$backtourl;
                               }
                               $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
                           }
                       }
                   }
                 if ($anchor ne '') {                  if ($anchor ne '') {
                     $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');                      $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
                 }                  }
Line 6473  sub editing_js { Line 6616  sub editing_js {
     }      }
   
     my $fieldsets = "'ext','doc'";      my $fieldsets = "'ext','doc'";
     if ($posslti) {  
         $fieldsets .= ",'tool'";  
     }  
     unless ($main_container_page) {      unless ($main_container_page) {
         $fieldsets .=",'ims'";          $fieldsets .=",'ims'";
     }      }
     if ($supplementalflag) {      if ($supplementalflag) {
         $fieldsets = "'suppext','suppdoc'";          $fieldsets = "'suppext','suppdoc'";
         if ($posslti) {  
             $fieldsets .= ",'supptool'";  
         }  
     }      }
   
     my $jsmakefunctions;      my $jsmakefunctions;
Line 6680  function toggleUpload(caller) { Line 6817  function toggleUpload(caller) {
             }              }
         }          }
         document.getElementById('upload'+blocks[i]+'form').style.display=disp;          document.getElementById('upload'+blocks[i]+'form').style.display=disp;
         if ((caller == 'tool') || (caller == 'supptool')) {  
             if (disp == 'block') {  
                 if (document.getElementById('LC_exttoolid')) {  
                     var toolselector = document.getElementById('LC_exttoolid');  
                     var suppflag = 0;  
                     if (caller == 'supptool') {  
                         suppflag = 1;  
                     }  
                     currForm = document.getElementById('new'+caller);  
                     updateExttool(toolselector,currForm,suppflag);  
                 }  
             }  
         }  
     }      }
     resize_scrollbox('contentscroll','1','1');      resize_scrollbox('contentscroll','1','1');
     return;      return;
Line 7670  check on this Line 7794  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.89


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