Diff for /loncom/interface/londocs.pm between versions 1.629 and 1.660

version 1.629, 2017/05/10 20:32:27 version 1.660, 2019/04/11 14:22:35
Line 45  use Apache::lontemplate(); Line 45  use Apache::lontemplate();
 use Apache::lonsimplepage();  use Apache::lonsimplepage();
 use Apache::lonhomework();  use Apache::lonhomework();
 use Apache::lonpublisher();  use Apache::lonpublisher();
   use Apache::lonparmset();
   use Apache::loncourserespicker();
 use HTML::Entities;  use HTML::Entities;
 use HTML::TokeParser;  use HTML::TokeParser;
 use GDBM_File;  use GDBM_File;
Line 52  use File::MMagic; Line 54  use File::MMagic;
 use File::Copy;  use File::Copy;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Cwd;  use Cwd;
   use UUID::Tiny ':std';
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
   
 my $iconpath;  my $iconpath;
Line 603  sub recurse_html { Line 606  sub recurse_html {
                 } else {                  } else {
                     $relfile = $dependency;                      $relfile = $dependency;
                     $depurl = $currurlpath;                      $depurl = $currurlpath;
                     $depurl =~ s{[^/]+$}{};                        $depurl =~ s{[^/]+$}{};
                     $depurl .= $dependency;                      $depurl .= $dependency;
                     ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});                       ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
                 }                  }
                 next if ($relfile eq '');                  next if ($relfile eq '');
                 my $newname = $replacehash->{$container};                  my $newname = $replacehash->{$container};
Line 659  sub group_import { Line 662  sub group_import {
                 my $marker = $2;                  my $marker = $2;
                 my $info = $3;                  my $info = $3;
                 my ($toolid,%toolhash,%toolsettings);                  my ($toolid,%toolhash,%toolsettings);
                 my @extras = ('linktext','explanation','crslabel','crstitle');                  my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
                 my @toolinfo = split(/:/,$info);                  my @toolinfo = split(/:/,$info);
                 if ($residx) {                  if ($residx) {
                     %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);                      %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
Line 669  sub group_import { Line 672  sub group_import {
                 }                  }
                 $toolid =~ s/\D//g;                  $toolid =~ s/\D//g;
                 ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},                  ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
                  $toolhash{'linktext'},$toolhash{'explanation'},                   $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
                  $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo;                   $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
                 foreach my $item (@extras) {                  foreach my $item (@extras) {
                     $toolhash{$item} = &unescape($toolhash{$item});                      $toolhash{$item} = &unescape($toolhash{$item});
                 }                  }
                   if ($folder =~ /^supplemental/) {
                       delete($toolhash{'gradable'});
                   } else {
                       $toolhash{'gradable'} =~ s/\D+//g;
                   }
                 if (ref($ltitoolsref) eq 'HASH') {                  if (ref($ltitoolsref) eq 'HASH') {
                     my @deleted;  
                     if (ref($ltitoolsref->{$toolid}) eq 'HASH') {                      if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
                           my @deleted;
                         $toolhash{'id'} = $toolid;                          $toolhash{'id'} = $toolid;
                         if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||                          if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
                             ($toolhash{'target'} eq 'window')) {                              ($toolhash{'target'} eq 'window')) {
Line 697  sub group_import { Line 705  sub group_import {
                         } elsif ($residx) {                          } elsif ($residx) {
                             $toolhash{'target'} = $toolsettings{'target'};                              $toolhash{'target'} = $toolsettings{'target'};
                             if ($toolhash{'target'} eq 'window') {                              if ($toolhash{'target'} eq 'window') {
                                 foreach my $item ('width','height') {                                   foreach my $item ('width','height') {
                                     $toolhash{$item} = $toolsettings{$item};                                      $toolhash{$item} = $toolsettings{$item};
                                 }                                  }
                             }                              }
Line 751  sub group_import { Line 759  sub group_import {
                                 }                                  }
                             }                              }
                         }                          }
                           if ($toolhash{'passback'}) {
                               my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                               $toolhash{'gradesecret'} = $gradesecret;
                               $toolhash{'gradesecretdate'} = time;
                           }
                           if ($toolhash{'roster'}) {
                               my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
                               $toolhash{'rostersecret'} = $rostersecret;
                               $toolhash{'rostersecretdate'} = time;
                           }
                           my $changegradable;
                           if (($residx) && ($folder =~ /^default/)) {
                               if ($toolsettings{'gradable'}) {
                                   unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
                                       push(@deleted,'gradable');
                                       $changegradable = 1;
                                   }
                               } elsif ($toolhash{'gradable'}) {
                                   $changegradable = 1;
                               }
                               if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
                                   $changegradable = 1;
                                   if ($toolsettings{'gradable'}) {
                                       $toolhash{'gradable'} = 1;
                                   }
                               }
                           }
                         my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);                          my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
                         if ($putres eq 'ok') {                          if ($putres eq 'ok') {
                             if (@deleted) {                              if (@deleted) {
                                 &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);                                  &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
                             }                               }
                               if (($changegradable) && ($folder =~ /^default/)) {
                                   my $val;
                                   if ($toolhash{'gradable'}) {
                                       $val = 'yes';
                                   } else {
                                       $val = 'no';
                                   }
                                   &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
                                                                 'string_yesno');
                                   &remember_parms($residx,'gradable','set',$val);
                               }
                           } else {
                               return (&mt('Failed to save update to external tool.'),1);
                         }                          }
                     }                      }
                 }                  }
Line 812  $initialtext Line 860  $initialtext
 </html>  </html>
 END  END
                 $env{'form.output'}=$newhtml;                  $env{'form.output'}=$newhtml;
                 my $result =                   my $result =
                     &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,                      &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
                                                           'output',                                                            'output',
                                                           "$filepath/$residx/$fname.html");                                                            "$filepath/$residx/$fname.html");
Line 971  sub docs_change_log { Line 1019  sub docs_change_log {
     if ($supplementalflag) {      if ($supplementalflag) {
         $tid = 2;          $tid = 2;
     }      }
     my ($breadcrumbtrail) =       my ($breadcrumbtrail) =
         &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);          &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
     $r->print($breadcrumbtrail.      $r->print($breadcrumbtrail.
               &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,                &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
Line 993  sub docs_change_log { Line 1041  sub docs_change_log {
     'encrypturl'     => 'URL hidden',      'encrypturl'     => 'URL hidden',
     'randompick'     => 'Randomly pick',      'randompick'     => 'Randomly pick',
     'randomorder'    => 'Randomly ordered',      'randomorder'    => 'Randomly ordered',
               'gradable'       => 'Grade can be assigned to External Tool',
     'set'            => 'set to',      'set'            => 'set to',
     'del'            => 'deleted');      'del'            => 'deleted');
     my $filter = &Apache::loncommon::display_filter('docslog')."\n".      my $filter = &Apache::loncommon::display_filter('docslog')."\n".
Line 1100  sub docs_change_log { Line 1149  sub docs_change_log {
  $r->print('</ul>');   $r->print('</ul>');
  if ($docslog{$id}{'logentry'}{'parameter_res'}) {   if ($docslog{$id}{'logentry'}{'parameter_res'}) {
     $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');      $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
     foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {      foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
  if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {   if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
 # FIXME: internationalization seems wrong here  # FIXME: internationalization seems wrong here
     $r->print('<li>'.      $r->print('<li>'.
Line 1170  sub update_paste_buffer { Line 1219  sub update_paste_buffer {
         foreach my $suffix (@currpaste) {          foreach my $suffix (@currpaste) {
              my $cid = $env{'docs.markedcopy_crs_'.$suffix};               my $cid = $env{'docs.markedcopy_crs_'.$suffix};
              my $url = $env{'docs.markedcopy_url_'.$suffix};               my $url = $env{'docs.markedcopy_url_'.$suffix};
              my $mapidx = $env{'docs.markedcopy_map_'.$suffix};                          my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
              if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&               if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
                  ($url ne '')) {                   ($url ne '')) {
                  $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;                   $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
Line 1672  sub do_paste_from_buffer { Line 1721  sub do_paste_from_buffer {
             $srcdom{$suffix} = $srcd;              $srcdom{$suffix} = $srcd;
             $srcnum{$suffix} = $srcn;              $srcnum{$suffix} = $srcn;
         } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||          } 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)$}) ||
             my $srctype= $1;                   ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
             my ($srcd,$srcn) = split(/_/,$cid);              my ($srcd,$srcn) = split(/_/,$cid);
 # When paste buffer was populated using an active role in a different course  # When paste buffer was populated using an active role in a different course
 # check for mdc privilege in the course from which the resource was pasted  # check for mdc privilege in the course from which the resource was pasted
Line 1683  sub do_paste_from_buffer { Line 1732  sub do_paste_from_buffer {
                     next;                      next;
                 }                  }
             }              }
             if (($srctype eq 'ext.tool') && ($srcd ne $coursedom)) {  # 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 (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
                 $notindom{$suffix} = 1;                  $notindom{$suffix} = 1;
                 next;                  next;
             }              }
Line 1768  sub do_paste_from_buffer { Line 1819  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) {
Line 1793  sub do_paste_from_buffer { Line 1837  sub do_paste_from_buffer {
         if ($is_map{$suffix}) {          if ($is_map{$suffix}) {
 # If pasting a map, check if map contains other maps  # If pasting a map, check if map contains other maps
             my (%hierarchy,%titles);              my (%hierarchy,%titles);
               if (($folder =~ /^default/) && (!$donechk)) {
                   $allmaps =
                       &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
                                                            $env{"course.$env{'request.course.id'}.home"},
                                                            $env{'request.course.id'});
                   $donechk = 1;
               }
             &contained_map_check($url,$folder,$coursenum,$coursedom,              &contained_map_check($url,$folder,$coursenum,$coursedom,
                                  \%removefrommap,\%removeparam,\%addedmaps,                                   \%removefrommap,\%removeparam,\%addedmaps,
                                  \%hierarchy,\%titles,$allmaps);                                   \%hierarchy,\%titles,$allmaps);
Line 1850  sub do_paste_from_buffer { Line 1901  sub do_paste_from_buffer {
         }          }
         if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {          if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
             my $prefix = $1;              my $prefix = $1;
             my $fromothercrs;               my $fromothercrs;
             #need to copy the db contents to a new one, unless this is a move.              #need to copy the db contents to a new one, unless this is a move.
             my %info = (              my %info = (
                          src  => $url,                           src  => $url,
                          cdom => $coursedom,                           cdom => $coursedom,
                          cnum => $coursenum,                           cnum => $coursenum,
                        );                         );
               if ($prefix eq 'ext.tool') {
                   if ($prefixchg{$suffix} eq 'docstosupp') {
                       $info{'delgradable'} = 1;
                   }
               }
             if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {              if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
                 unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {                  unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
                     $fromothercrs = 1;                      $fromothercrs = 1;
Line 1865  sub do_paste_from_buffer { Line 1921  sub do_paste_from_buffer {
                 }                  }
             }              }
             unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {              unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
                 my (%lockerr,$msg);                   my (%lockerr,$msg);
                 my ($newurl,$result,$errtext) =                  my ($newurl,$result,$errtext) =
                     &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);                      &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
                 if ($result eq 'ok') {                  if ($result eq 'ok') {
Line 1924  sub do_paste_from_buffer { Line 1980  sub do_paste_from_buffer {
                     if ($newdocsdir eq '') {                      if ($newdocsdir eq '') {
                         $newdocsdir = 'default';                          $newdocsdir = 'default';
                     }                      }
                     if (($prefixchg{$suffix}) ||                       if (($prefixchg{$suffix}) ||
                         ($srcdom{$suffix} ne $coursedom) ||                           ($srcdom{$suffix} ne $coursedom) ||
                         ($srcnum{$suffix} ne $coursenum) ||                          ($srcnum{$suffix} ne $coursenum) ||
                         ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {                          ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
                         my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";                          my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
Line 1948  sub do_paste_from_buffer { Line 2004  sub do_paste_from_buffer {
                     &copy_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},                      &copy_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
                                           $coursedom,$coursenum,$template,$newidx,"$folder.$container");                                            $coursedom,$coursenum,$template,$newidx,"$folder.$container");
                 }                  }
               } elsif ($url =~ /ext\.tool$/) {
                   if (($newidx) && ($folder=~/^default/)) {
                       my $marker = (split(m{/},$url))[4];
                       my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
                       my $val = 'no';
                       if ($toolsettings{'gradable'}) {
                           $val = 'yes';
                       }
                       &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
                                                     'string_yesno');
                       &remember_parms($newidx,'gradable','set',$val);
                   }
             }              }
             $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).              $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                                               ':'.$ext.':normal:res';                                                ':'.$ext.':normal:res';
Line 2164  sub dbcopy { Line 2232  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 2194  sub dbcopy { Line 2264  sub dbcopy {
                         }                          }
                     }                      }
                     $db_name =~ s{_\d*$ }{_$suffix}x;                      $db_name =~ s{_\d*$ }{_$suffix}x;
                       if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
                           delete($contents{'gradable'});
                       }
                     $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') {
Line 2478  sub url_paste_fixups { Line 2551  sub url_paste_fixups {
                         $changed = 1;                          $changed = 1;
                     }                      }
                 }                  }
             } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {              } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
                 next if ($skip);                  next if ($skip);
                 my $srcdom = $1;                  my $srcdom = $1;
                 my $srcnum = $2;                  my $srcnum = $2;
                   my $rem = $3;
                   my ($is_exttool,$exttoolchg);
                   if ($rem =~ m{\d+/ext\.tool$}) {
                       $is_exttool = 1;
                   }
                 if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {                  if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
                     $rewrites->{$oldurl}{$id} = $ressrc;                      $rewrites->{$oldurl}{$id} = $ressrc;
                     $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;                      $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                     $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;                      $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                     $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;                      $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                     $changed = 1;                      $changed = 1;
                       if ($is_exttool) {
                           $exttoolchg = 1;
                       }
                   } elsif (($rem =~ m{\d+/ext\.tool$}) &&
                            ($env{'form.docs.markedcopy_options'} ne 'move')) {
                       $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
                       $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
                       $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
                       $changed = 1;
                       $exttoolchg = 1;
                   }
                   if (($is_exttool) && ($prefixchg)) {
                       if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
                           if ($exttoolchg) {
                               $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
                           }
                       }
                 }                  }
             } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {              } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
                 if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||                  if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
Line 2751  sub apply_fixups { Line 2846  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 2761  sub apply_fixups { Line 2857  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 2803  sub apply_fixups { Line 2899  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 2911  sub update_parameter { Line 3007  sub update_parameter {
                          'randomorder'    => {},                           'randomorder'    => {},
                       );                        );
         foreach my $which (keys(%allchecked)) {          foreach my $which (keys(%allchecked)) {
             $env{'form.all'.$which} =~ s/,$//;                 $env{'form.all'.$which} =~ s/,$//;
             if ($which eq 'randompick') {              if ($which eq 'randompick') {
                 foreach my $item (split(/,/,$env{'form.all'.$which})) {                  foreach my $item (split(/,/,$env{'form.all'.$which})) {
                     my ($res,$value) = split(/:/,$item);                      my ($res,$value) = split(/:/,$item);
Line 3014  sub update_parameter { Line 3110  sub update_parameter {
   
 sub handle_edit_cmd {  sub handle_edit_cmd {
     my ($coursenum,$coursedom) =@_;      my ($coursenum,$coursedom) =@_;
       my $haschanges = 0;
     if ($env{'form.cmd'} eq '') {      if ($env{'form.cmd'} eq '') {
         return 0;          return $haschanges; 
     }      }
     my ($cmd,$idx)=split('_',$env{'form.cmd'});      my ($cmd,$idx)=split('_',$env{'form.cmd'});
   
Line 3030  sub handle_edit_cmd { Line 3127  sub handle_edit_cmd {
     &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);      &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
  }   }
  splice(@LONCAPA::map::order, $idx, 1);   splice(@LONCAPA::map::order, $idx, 1);
           $haschanges = 1;
     } elsif ($cmd eq 'cut') {      } elsif ($cmd eq 'cut') {
  &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);   &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
  splice(@LONCAPA::map::order, $idx, 1);   splice(@LONCAPA::map::order, $idx, 1);
           $haschanges = 1;
     } elsif ($cmd eq 'up'      } elsif ($cmd eq 'up'
      && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {       && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
  @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];   @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
           $haschanges = 1;
     } elsif ($cmd eq 'down'      } elsif ($cmd eq 'down'
      && defined($LONCAPA::map::order[$idx+1])) {       && defined($LONCAPA::map::order[$idx+1])) {
  @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];   @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
           $haschanges = 1;
     } elsif ($cmd eq 'rename') {      } elsif ($cmd eq 'rename') {
  my $comment = &LONCAPA::map::qtunescape($env{'form.title'});   my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
  if ($comment=~/\S/) {   if ($comment=~/\S/) {
Line 3052  sub handle_edit_cmd { Line 3149  sub handle_edit_cmd {
 # Devalidate title cache  # Devalidate title cache
  my $renamed_url=&LONCAPA::map::qtescape($url);   my $renamed_url=&LONCAPA::map::qtescape($url);
  &Apache::lonnet::devalidate_title_cache($renamed_url);   &Apache::lonnet::devalidate_title_cache($renamed_url);
           $haschanges = 1;
     } else {      } elsif ($cmd eq 'setalias') {
  return 0;          my $newvalue = $env{'form.alias'};
           if ($newvalue ne '') {
               unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
                   &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
                                                 'string');
                   &remember_parms($idx,'mapalias','set',$newvalue);
                   $haschanges = 1;
               }
           }
       } elsif ($cmd eq 'delalias') {
           my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];  
           if ($current ne '') {
               &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
               &remember_parms($idx,'mapalias','del');
               $haschanges = 1;
           }
     }      }
     return 1;      return $haschanges;
 }  }
   
 sub editor {  sub editor {
Line 3180  sub editor { Line 3292  sub editor {
 # Rename, cut, copy or remove a single resource  # Rename, cut, copy or remove a single resource
  if (&handle_edit_cmd($coursenum,$coursedom)) {   if (&handle_edit_cmd($coursenum,$coursedom)) {
             my $contentchg;              my $contentchg;
             if ($env{'form.cmd'} =~ m{^(remove|cut)_}) {              if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
                 $contentchg = 1;                  $contentchg = 1;
             }              }
     ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);      ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
Line 3420  sub editor { Line 3532  sub editor {
                           .&Apache::loncommon::start_data_table(undef,'contentlist')                            .&Apache::loncommon::start_data_table(undef,'contentlist')
                           .&Apache::loncommon::start_data_table_header_row()                            .&Apache::loncommon::start_data_table_header_row()
                           .'<th colspan="2">'.&mt('Move').'</th>'                            .'<th colspan="2">'.&mt('Move').'</th>'
                           .'<th colspan="2">'.&mt('Actions').'</th>'                            .'<th colspan="3">'.&mt('Actions').'</th>'
                           .'<th>'.&mt('Document').'</th>';                            .'<th>'.&mt('Document').'</th>';
                 if ($folder !~ /^supplemental/) {                  if ($folder !~ /^supplemental/) {
                     $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';                      $to_show .= '<th colspan="2">'.&mt('Settings').'</th>';
                 }                  }
                 $to_show .= &Apache::loncommon::end_data_table_header_row();                  $to_show .= &Apache::loncommon::end_data_table_header_row();
                 if ($folder !~ /^supplemental/) {                  if ($folder !~ /^supplemental/) {
Line 3441  sub editor { Line 3553  sub editor {
                     if (@allidx > 0) {                      if (@allidx > 0) {
                         my $path;                          my $path;
                         if ($env{'form.folderpath'}) {                          if ($env{'form.folderpath'}) {
                             $path =                               $path =
                                 &HTML::Entities::encode($env{'form.folderpath'},'<>&"');                                  &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
                         }                          }
                         if (@allidx > 1) {                          if (@allidx > 1) {
                             $to_show .=                               $to_show .=
                                 &Apache::loncommon::continue_data_table_row().                                  &Apache::loncommon::continue_data_table_row().
                                 '<td colspan="2">&nbsp;</td>'.                                  '<td colspan="2">&nbsp;</td>'.
                                 '<td>'.                                  '<td>'.
                                 &multiple_check_form('actions',\%lists,$canedit).                                  &multiple_check_form('actions',\%lists,$canedit).
                                 '</td>'.                                  '</td>'.
                                 '<td>&nbsp;</td>'.                                  '<td colspan="3">&nbsp;</td>'.
                                 '<td>&nbsp;</td>'.                                  '<td colspan="2">'.
                                 '<td colspan="4">'.  
                                 &multiple_check_form('settings',\%lists,$canedit).                                  &multiple_check_form('settings',\%lists,$canedit).
                                 '</td>'.                                  '</td>'.
                                 &Apache::loncommon::end_data_table_row();                                  &Apache::loncommon::end_data_table_row();
Line 3693  sub process_file_upload { Line 3804  sub process_file_upload {
                     my $uploadphase = 'upload_embedded';                      my $uploadphase = 'upload_embedded';
                     my $primaryurl = &HTML::Entities::encode($url,'<>&"');                      my $primaryurl = &HTML::Entities::encode($url,'<>&"');
     my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);       my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx); 
                     my ($embedded,$num) =                       my ($embedded,$num) =
                         &Apache::loncommon::ask_for_embedded_content(                          &Apache::loncommon::ask_for_embedded_content(
                             '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});                              '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
                     if ($embedded) {                      if ($embedded) {
Line 3801  sub entryline { Line 3912  sub entryline {
     my $line=&Apache::loncommon::start_data_table_row();      my $line=&Apache::loncommon::start_data_table_row();
     my ($form_start,$form_end,$form_common,$form_param);      my ($form_start,$form_end,$form_common,$form_param);
 # Edit commands  # Edit commands
     my ($esc_path, $path, $symb);      my ($esc_path, $path, $symb, $curralias);
     if ($env{'form.folderpath'}) {      if ($env{'form.folderpath'}) {
  $esc_path=&escape($env{'form.folderpath'});   $esc_path=&escape($env{'form.folderpath'});
  $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');   $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
Line 3870  END Line 3981  END
                 'ct' => 'Cut',                  'ct' => 'Cut',
  'rn' => 'Rename',   'rn' => 'Rename',
  'cp' => 'Copy',   'cp' => 'Copy',
                   'da' => 'Unset alias', 
                   'sa' => 'Set alias',
                 'ex' => 'External Resource',                  'ex' => 'External Resource',
                 'et' => 'External Tool',                  'et' => 'External Tool',
                 'ed' => 'Edit',                  'ed' => 'Edit',
Line 3900  END Line 4013  END
             ($url!~/$LONCAPA::assess_page_seq_re/)) {              ($url!~/$LONCAPA::assess_page_seq_re/)) {
             $confirm_removal = 1;              $confirm_removal = 1;
         }          }
           if ($url =~ /$LONCAPA::assess_re/) {
               $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
           }
   
  if ($denied{'copy'}) {   if ($denied{'copy'}) {
             $copylink=(<<ENDCOPY)              $copylink=(<<ENDCOPY)
Line 4055  END Line 4171  END
             } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {              } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
                 if (($ENV{'SERVER_PORT'} == 443) &&                  if (($ENV{'SERVER_PORT'} == 443) &&
                     ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {                      ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
                     $url .= '?usehttp=1';                      unless (&Apache::lonnet::uses_sts()) {
                           $url .= '?usehttp=1';
                       }
                     $nomodal = 1;                      $nomodal = 1;
                 }                  }
             }              }
Line 4065  END Line 4183  END
                     if ($url =~ /^([^#]+)#([^#]+)$/) {                      if ($url =~ /^([^#]+)#([^#]+)$/) {
                         $url = $1;                          $url = $1;
                         $anchor = $2;                          $anchor = $2;
                         if ($symb =~ m{^([^#]+)\Q#$anchor\E$}) {                          my $escan = &escape('#');
                             $shownsymb = $1.&escape('#').$anchor;                          $shownsymb =~ s/^([^\#]+)#([^\#]+)$/$1$escan$2/;
                         }  
                     }                      }
                 }                  }
                 unless ($env{'request.role.adv'}) {                  unless ($env{'request.role.adv'}) {
Line 4080  END Line 4197  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 4101  END Line 4218  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 4121  END Line 4238  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)) {
                     if ($hostname ne '') {                      unless (&Apache::lonnet::uses_sts()) {
                         $url = 'http://'.$hostname.$url;                          if ($hostname ne '') {
                               $url = 'http://'.$hostname.$url;
                           }
                           $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
                     }                      }
                     $nomodal = 1;                      $nomodal = 1;
                 }                  }
Line 4130  END Line 4250  END
         } 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://})) {
                 if ($hostname ne '') {                  unless (&Apache::lonnet::uses_sts()) {
                     $url = 'http://'.$hostname.$url;                      if ($hostname ne '') {
                           $url = 'http://'.$hostname.$url;
                       }
                       $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';
                 }                  }
                 $url .= (($url =~ /\?/) ? '&amp;':'?').'usehttp=1';  
                 $nomodal = 1;                  $nomodal = 1;
             }              }
         }          }
Line 4182  END Line 4304  END
                     }                      }
                 }                  }
             }              }
               
 # Append randompick number, hidden, and encrypted with ":" to foldername,  # Append randompick number, hidden, and encrypted with ":" to foldername,
 # so it gets transferred between levels  # so it gets transferred between levels
     $folderpath.=$containerarg.'&'.$foldername.      $folderpath.=$containerarg.'&'.$foldername.
Line 4243  $form_end; Line 4365  $form_end;
     }      }
     my ($tdalign,$tdwidth);      my ($tdalign,$tdwidth);
     if ($allowed) {      if ($allowed) {
         my $fileloc =           my $fileloc =
             &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));              &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
         if ($isexternal) {          if ($isexternal) {
             ($editlink,$extresform) =               ($editlink,$extresform) =
                 &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,                  &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
                                                      undef,undef,undef,undef,undef,undef,                                                       undef,undef,undef,undef,undef,undef,
                                                      undef,$disabled);                                                       undef,$disabled);
Line 4263  $form_end; Line 4385  $form_end;
                 if ($supplementalflag) {                  if ($supplementalflag) {
                     $suppanchor = $anchor;                      $suppanchor = $anchor;
                 }                  }
                 my $jscall =                   my $jscall =
                     &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,                      &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
                                                             $switchserver,                                                              $switchserver,
                                                             $forceedit,                                                              $forceedit,
Line 4287  $form_end; Line 4409  $form_end;
         $reinit = &mt('(re-initialize course to access)');          $reinit = &mt('(re-initialize course to access)');
     }      }
     $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;      $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
       if ($orig_url =~ /$LONCAPA::assess_re/) {
           $line.= '<br />';
           if ($curralias ne '') {
               $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                      $lt{'da'}.'</a></span>';
           } else {
               $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
                      $lt{'sa'}.'</a></span>';
           }
       }
       $line.='</td><td>';
     my $link;      my $link;
     if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {      if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
        $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';         $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
Line 4303  $form_end; Line 4436  $form_end;
        } else {         } else {
            $link = $url;             $link = $url;
        }         }
        $link = &js_escape($link.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.         $link = &js_escape($link.(($url=~/\?/)?'&amp;':'?').'inhibitmenu=yes'.$anchor);
                                                (($anchor ne '')?$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 4326  $form_end; Line 4458  $form_end;
            $line.=&Apache::loncommon::modal_link($link,$title,600,500);             $line.=&Apache::loncommon::modal_link($link,$title,600,500);
        }         }
     } elsif (($hiddenfolder) || ($hiddenres)) {      } elsif (($hiddenfolder) || ($hiddenres)) {
        $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';         $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
     } else {      } else {
        $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';         $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
     }      }
     $line.="$extresform</td>";      if (($allowed) && ($curralias ne '')) {
           $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
       } else {
           $line .= $extresform;
       }
       $line .= '</td>';
     $rand_pick_text = '&nbsp;' if ($rand_pick_text eq '');      $rand_pick_text = '&nbsp;' if ($rand_pick_text eq '');
     $rand_order_text = '&nbsp;' if ($rand_order_text eq '');      $rand_order_text = '&nbsp;' if ($rand_order_text eq '');
     if (($allowed) && ($folder!~/^supplemental/)) {      if (($allowed) && ($folder!~/^supplemental/)) {
Line 4475  sub new_timebased_suffix { Line 4612  sub new_timebased_suffix {
         }          }
     }      }
     if ($freedlock ne 'ok') {      if ($freedlock ne 'ok') {
         $locknotfreed =           $locknotfreed =
             '<div class="LC_error">'.              '<div class="LC_error">'.
             &mt('There was a problem removing a lockfile.').' ';              &mt('There was a problem removing a lockfile.').' ';
         if ($type eq 'paste') {          if ($type eq 'paste') {
Line 4548  sub untiehash { Line 4685  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 4563  sub checkonthis { Line 4700  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 4600  sub checkonthis { Line 4749  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 4614  sub checkonthis { Line 4763  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 4666  sub list_symbs { Line 4818  sub list_symbs {
     $r->print(&endContentScreen());      $r->print(&endContentScreen());
 }  }
   
   sub short_urls {
       my ($r,$canedit) = @_;
       my $crstype = &Apache::loncommon::course_type();
       my $formname = 'shortenurl';
       $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
       $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
       $r->print(&startContentScreen('tools'));
       my ($navmap,$errormsg) =
           &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
       my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
       my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
       my (%maps,%resources,%titles);
       if (!ref($navmap)) {
           $r->print($errormsg.
                     &endContentScreen());
           return '';
       } else {
           $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
           $r->rflush();
           my $readonly;
           if ($canedit) {
               my ($numnew,$errors) = &Apache::loncommon::make_short_symbs($cdom,$cnum,$navmap);
               if ($numnew) {
                   $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
               }
               if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
                   $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
                   foreach my $error (@{$errors}) {
                       $r->print('<li>'.$error.'</li>');
                   }
                   $r->print('</ul><br />');
               }
           } else {
               $readonly = 1;
           }
           my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
           $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
                                                                undef,undef,undef,undef,undef,\%currtiny,$readonly));
       }
       $r->print(&endContentScreen());
   }
   
 sub verifycontent {  sub contentverifyform {
     my ($r) = @_;      my ($r) = @_;
     my $crstype = &Apache::loncommon::course_type();      my $crstype = &Apache::loncommon::course_type();
     $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));      $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));      $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
     $r->print(&startContentScreen('tools'));      $r->print(&startContentScreen('tools'));
       $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
       $r->print('<form method="post" action="/adm/coursedocs"><p>'.
                 &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
                 '&nbsp;<span class="LC_nobreak">'.
                 '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
                 &mt('No').'</label>'.('&nbsp;'x2).
                 '<label><input type="radio" name="checkstale" value="1" />'.
                 &mt('Yes').'</label></span></p><p>'.
                 '<input type="submit" value="'.&mt('Verify content').' "/>'.
                 '<input type="hidden" value="1" name="tools" />'.
                 '<input type="hidden" value="1" name="verify" /></p></form>');
       $r->print(&endContentScreen());
       return;
   }
   
   sub verifycontent {
       my ($r,$checkstale) = @_;
       my $crstype = &Apache::loncommon::course_type();
       $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
       $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
       $r->print(&startContentScreen('tools'));
     $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');       $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>'); 
    $hashtied=0;     $hashtied=0;
    undef %alreadyseen;     undef %alreadyseen;
Line 4689  sub verifycontent { Line 4903  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 4697  sub verifycontent { Line 4911  sub verifycontent {
     $r->print(&endContentScreen());      $r->print(&endContentScreen());
 }  }
   
   
 sub devalidateversioncache {  sub devalidateversioncache {
     my $src=shift;      my $src=shift;
     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.      &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
Line 5017  sub changewarning { Line 5230  sub changewarning {
     if (!defined($message)) {      if (!defined($message)) {
  $message='Changes will become active for your current session after [_1], or the next time you log in.';   $message='Changes will become active for your current session after [_1], or the next time you log in.';
     }      }
       my $windowname = 'loncapaclient';
       if ($env{'request.lti.login'}) {
           $windowname .= 'lti';
       }
     $r->print("\n\n".      $r->print("\n\n".
 '<script type="text/javascript">'."\n".  '<script type="text/javascript">'."\n".
 '// <![CDATA['."\n".  '// <![CDATA['."\n".
 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".  'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
 '// ]]>'."\n".  '// ]]>'."\n".
 '</script>'."\n".  '</script>'."\n".
 '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.  '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
 '<input type="hidden" name="orgurl" value="'.$url.  '<input type="hidden" name="orgurl" value="'.$url.
 '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.  '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
 &mt($message,' <input type="hidden" name="'.  &mt($message,' <input type="hidden" name="'.
Line 5160  sub handler { Line 5377  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);
     } elsif ($allowed && $env{'form.shorturls'}) {
         &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
         &short_urls($r,$canedit);
   } elsif ($allowed && $env{'form.docslog'}) {    } elsif ($allowed && $env{'form.docslog'}) {
       &init_breadcrumbs('docslog','Show Log');        &init_breadcrumbs('docslog','Show Log');
       my $folder = $env{'form.folder'};        my $folder = $env{'form.folder'};
Line 5229  sub handler { Line 5465  sub handler {
                       $r->internal_redirect($redirect);                        $r->internal_redirect($redirect);
                       return OK;                        return OK;
                   }                    }
                 } else {
                     $r->internal_redirect($redirect);
               }                }
           }            }
       }        }
Line 5242  sub handler { Line 5480  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 5264  sub handler { Line 5522  sub handler {
     my $toolsflag=0;      my $toolsflag=0;
     if ($env{'form.tools'}) { $toolsflag=1; }      if ($env{'form.tools'}) { $toolsflag=1; }
   
       if ($env{'form.folderpath'} ne '') {
           my @items = split(/\&/,$env{'form.folderpath'});
           my $badpath;
           for (my $i=0; $i<@items; $i++) {
               my $odd = $i%2;
               if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
                   $badpath = 1;
               } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
                   $badpath = 1;
               }
               last if ($badpath);
           }
           if ($badpath) {
               delete($env{'form.folderpath'});
           }
       }
   
       if ($env{'form.supppath'} ne '') {
           my @items = split(/\&/,$env{'form.supppath'});
           my $badpath;
           for (my $i=0; $i<@items; $i++) {
               my $odd = $i%2;
               if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
                   $badpath = 1; 
               }
               last if ($badpath);
           }
           if ($badpath) {
               delete($env{'form.supppath'});
           }
       }
   
     my $script='';      my $script='';
     my $showdoc=0;      my $showdoc=0;
     my $addentries = {};      my $addentries = {};
Line 5438  sub handler { Line 5728  sub handler {
             my $tid = 1;              my $tid = 1;
             my @tabids;              my @tabids;
             if ($supplementalflag) {              if ($supplementalflag) {
                 @tabids = ('002','ee2','ff2');                  @tabids = ('002','dd2','ee2','ff2');
                 $tid = 2;                  $tid = 2;
             } else {              } else {
                 @tabids = ('aa1','bb1','cc1','ff1');                  @tabids = ('aa1','bb1','cc1','ff1');
Line 5448  sub handler { Line 5738  sub handler {
                 }                  }
             }              }
             my $tabidstr = join("','",@tabids);              my $tabidstr = join("','",@tabids);
             %ltitools = &Apache::lonnet::get_domain_ltitools($coursedom);              %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
             my $posslti = keys(%ltitools);              my $posslti = keys(%ltitools);
             my $hostname = $r->hostname();              my $hostname = $r->hostname();
     $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,      $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
Line 5536  sub handler { Line 5826  sub handler {
   undef($hadchanges);    undef($hadchanges);
           $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,            $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
                                               \%allfiles,\%codebase,$context,$crstype);                                                \%allfiles,\%codebase,$context,$crstype);
             undef($navmap);
   if ($hadchanges) {    if ($hadchanges) {
       &mark_hash_old();        &mark_hash_old();
   }    }
Line 5551  sub handler { Line 5842  sub handler {
           my ($destination,$dir_root) = &embedded_destination();            my ($destination,$dir_root) = &embedded_destination();
           my $url_root = '/uploaded/'.$docudom.'/'.$docuname;            my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
           my $actionurl = '/adm/coursedocs';            my $actionurl = '/adm/coursedocs';
           my ($result,$flag) =             my ($result,$flag) =
               &Apache::loncommon::upload_embedded('coursedoc',$destination,                &Apache::loncommon::upload_embedded('coursedoc',$destination,
                   $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,                    $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
                   $actionurl);                    $actionurl);
Line 5562  sub handler { Line 5853  sub handler {
           my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};            my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
           my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};            my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
           my ($destination,$dir_root) = &embedded_destination();            my ($destination,$dir_root) = &embedded_destination();
           my $result =             my $result =
               &Apache::loncommon::modify_html_refs('coursedoc',$destination,                &Apache::loncommon::modify_html_refs('coursedoc',$destination,
                                                    $docuname,$docudom,undef,                                                     $docuname,$docudom,undef,
                                                    $dir_root);                                                     $dir_root);
           $r->print($result.&return_to_editor());               $r->print($result.&return_to_editor());
       } elsif ($env{'form.phase'} eq 'decompress_uploaded') {        } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
           $uploadphase = 'decompress_phase_one';            $uploadphase = 'decompress_phase_one';
           $r->print(&decompression_phase_one().            $r->print(&decompression_phase_one().
Line 5592  sub handler { Line 5883  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',
                 'imcr' => 'Import from Course Resources',                     'imcr' => 'Import from Course Resources',
                 'extr' => 'External Resource',                  'extr' => 'External Resource',
                 'extt' => 'External Tool',                  'extt' => 'External Tool',
                 'selm' => 'Select Map',                  'selm' => 'Select Map',
Line 5603  sub handler { Line 5894  sub handler {
                 'navc' => 'Table of Contents',                  'navc' => 'Table of Contents',
                 'sipa' => 'Simple Course Page',                  'sipa' => 'Simple Course Page',
                 'sipr' => 'Simple Problem',                  'sipr' => 'Simple Problem',
                 'webp' => 'Blank Web Page (editable)',                   'webp' => 'Blank Web Page (editable)',
                 'stpr' => 'Standard Problem',                  'stpr' => 'Standard Problem',
                 'news' => 'New sub-directory',                  'news' => 'New sub-directory',
                 'crpr' => 'Create Problem',                  'crpr' => 'Create Problem',
Line 5832  CRSFORM Line 6123  CRSFORM
    <input type="hidden" name="copyfolder" />     <input type="hidden" name="copyfolder" />
    $containertag     $containertag
  </form>   </form>
    <form name="aliasform" method="post" action="/adm/coursedocs">
      <input type="hidden" name="alias" />
      <input type="hidden" name="cmd" />
      $containertag
    </form>
   
 HIDDENFORM  HIDDENFORM
         $r->print(&makesimpleeditform($pathitem)."\n".          $r->print(&makesimpleeditform($pathitem)."\n".
Line 5868  HIDDENFORM Line 6164  HIDDENFORM
        }         }
        my $postexec='';         my $postexec='';
        if ($folder eq 'default') {         if ($folder eq 'default') {
              my $windowname = 'loncapaclient';
              if ($env{'request.lti.login'}) {
                  $windowname .= 'lti';
              }
            $r->print('<script type="text/javascript">'."\n"             $r->print('<script type="text/javascript">'."\n"
                     .'// <![CDATA['."\n"                      .'// <![CDATA['."\n"
                     .'this.window.name="loncapaclient";'."\n"                      .'this.window.name="'.$windowname.'";'."\n"
                     .'// ]]>'."\n"                      .'// ]]>'."\n"
                     .'</script>'."\n"                      .'</script>'."\n"
        );         );
Line 5883  HIDDENFORM Line 6183  HIDDENFORM
   
  my $newnavform=(<<NNFORM);   my $newnavform=(<<NNFORM);
  <form action="/adm/coursedocs" method="post" name="newnav">   <form action="/adm/coursedocs" method="post" name="newnav">
  <input type="hidden" name="active" value="ee" />   <input type="hidden" name="active" value="ff" />
  $pathitem   $pathitem
  <input type="hidden" name="importdetail"    <input type="hidden" name="importdetail" 
  value="$lt{'navc'}=/adm/navmaps" />   value="$lt{'navc'}=/adm/navmaps" />
Line 5893  HIDDENFORM Line 6193  HIDDENFORM
 NNFORM  NNFORM
  my $newsmppageform=(<<NSPFORM);   my $newsmppageform=(<<NSPFORM);
  <form action="/adm/coursedocs" method="post" name="newsmppg">   <form action="/adm/coursedocs" method="post" name="newsmppg">
  <input type="hidden" name="active" value="ee" />   <input type="hidden" name="active" value="ff" />
  $pathitem   $pathitem
  <input type="hidden" name="importdetail" value="" />   <input type="hidden" name="importdetail" value="" />
  <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>   <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
Line 5903  NSPFORM Line 6203  NSPFORM
   
  my $newsmpproblemform=(<<NSPROBFORM);   my $newsmpproblemform=(<<NSPROBFORM);
  <form action="/adm/coursedocs" method="post" name="newsmpproblem">   <form action="/adm/coursedocs" method="post" name="newsmpproblem">
  <input type="hidden" name="active" value="cc" />   <input type="hidden" name="active" value="dd" />
  $pathitem   $pathitem
  <input type="hidden" name="importdetail" value="" />   <input type="hidden" name="importdetail" value="" />
  <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>   <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
Line 5914  NSPROBFORM Line 6214  NSPROBFORM
   
  my $newdropboxform=(<<NDBFORM);   my $newdropboxform=(<<NDBFORM);
  <form action="/adm/coursedocs" method="post" name="newdropbox">   <form action="/adm/coursedocs" method="post" name="newdropbox">
  <input type="hidden" name="active" value="cc" />   <input type="hidden" name="active" value="dd" />
  $pathitem   $pathitem
  <input type="hidden" name="importdetail" value="" />   <input type="hidden" name="importdetail" value="" />
  <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>   <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
Line 5924  NDBFORM Line 6224  NDBFORM
   
  my $newexuploadform=(<<NEXUFORM);   my $newexuploadform=(<<NEXUFORM);
  <form action="/adm/coursedocs" method="post" name="newexamupload">   <form action="/adm/coursedocs" method="post" name="newexamupload">
  <input type="hidden" name="active" value="cc" />   <input type="hidden" name="active" value="dd" />
  $pathitem   $pathitem
  <input type="hidden" name="importdetail" value="" />   <input type="hidden" name="importdetail" value="" />
  <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>   <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
Line 5934  NEXUFORM Line 6234  NEXUFORM
   
  my $newbulform=(<<NBFORM);   my $newbulform=(<<NBFORM);
  <form action="/adm/coursedocs" method="post" name="newbul">   <form action="/adm/coursedocs" method="post" name="newbul">
  <input type="hidden" name="active" value="dd" />   <input type="hidden" name="active" value="ee" />
  $pathitem   $pathitem
  <input type="hidden" name="importdetail" value="" />   <input type="hidden" name="importdetail" value="" />
  <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>   <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
Line 5944  NBFORM Line 6244  NBFORM
   
  my $newaboutmeform=(<<NAMFORM);   my $newaboutmeform=(<<NAMFORM);
  <form action="/adm/coursedocs" method="post" name="newaboutme">   <form action="/adm/coursedocs" method="post" name="newaboutme">
  <input type="hidden" name="active" value="dd" />   <input type="hidden" name="active" value="ee" />
  $pathitem   $pathitem
  <input type="hidden" name="importdetail"    <input type="hidden" name="importdetail" 
  value="$plainname=/adm/$udom/$uname/aboutme" />   value="$plainname=/adm/$udom/$uname/aboutme" />
Line 5955  NAMFORM Line 6255  NAMFORM
   
  my $newaboutsomeoneform=(<<NASOFORM);   my $newaboutsomeoneform=(<<NASOFORM);
  <form action="/adm/coursedocs" method="post" name="newaboutsomeone">   <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
  <input type="hidden" name="active" value="dd" />   <input type="hidden" name="active" value="ee" />
  $pathitem   $pathitem
  <input type="hidden" name="importdetail" value="" />   <input type="hidden" name="importdetail" value="" />
  <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>   <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
Line 5964  NASOFORM Line 6264  NASOFORM
   
  my $newrosterform=(<<NROSTFORM);   my $newrosterform=(<<NROSTFORM);
  <form action="/adm/coursedocs" method="post" name="newroster">   <form action="/adm/coursedocs" method="post" name="newroster">
  <input type="hidden" name="active" value="dd" />   <input type="hidden" name="active" value="ee" />
  $pathitem   $pathitem
  <input type="hidden" name="importdetail"    <input type="hidden" name="importdetail" 
  value="$lt{'rost'}=/adm/viewclasslist" />   value="$lt{'rost'}=/adm/viewclasslist" />
Line 5985  NROSTFORM Line 6285  NROSTFORM
         }          }
         my $newwebpageform =(<<NWEBFORM);          my $newwebpageform =(<<NWEBFORM);
         <form action="/adm/coursedocs" method="post" name="newwebpage">          <form action="/adm/coursedocs" method="post" name="newwebpage">
         <input type="hidden" name="active" value="ee" />          <input type="hidden" name="active" value="ff" />
         $pathitem          $pathitem
         <input type="hidden" name="importdetail" value="$newwebpage" />          <input type="hidden" name="importdetail" value="$newwebpage" />
         <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>          <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
Line 6052  NWEBFORM Line 6352  NWEBFORM
                 $numauthor ++;                  $numauthor ++;
             }              }
         }          }
         my ($pickdir,$showtitle);;          my ($pickdir,$showtitle);
         if ($numauthor) {          if ($numauthor) {
             my @order;              my @order;
             my $defrole;              my $defrole;
Line 6168  NWEBFORM Line 6468  NWEBFORM
         <form action="/adm/coursedocs" method="post" name="courseresform">          <form action="/adm/coursedocs" method="post" name="courseresform">
         <fieldset id="crsresform" style="display:none;">          <fieldset id="crsresform" style="display:none;">
         <legend>$lt{'stpr'}</legend>          <legend>$lt{'stpr'}</legend>
         <input type="hidden" name="active" value="ee" />          <input type="hidden" name="active" value="bb" />
         <p>          <p>
         $pickdir          $pickdir
         <span class="LC_nobreak">$lt{'news'}?&nbsp;          <span class="LC_nobreak">$lt{'news'}?&nbsp;
Line 6256  NSYLFORM Line 6556  NSYLFORM
   
  my $newgroupfileform=(<<NGFFORM);   my $newgroupfileform=(<<NGFFORM);
  <form action="/adm/coursedocs" method="post" name="newgroupfiles">   <form action="/adm/coursedocs" method="post" name="newgroupfiles">
  <input type="hidden" name="active" value="dd" />   <input type="hidden" name="active" value="ee" />
  $pathitem   $pathitem
  <input type="hidden" name="importdetail"   <input type="hidden" name="importdetail"
  value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />   value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
Line 6273  NGFFORM Line 6573  NGFFORM
         );          );
         $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));          $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
   
           my @external = (
         my @importdoc = (          {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
         {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}  
         );          );
         if (keys(%ltitools)) {          if (keys(%ltitools)) {
             push(@importdoc,              push(@external,
                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleUpload(\'tool\');" />'=>$exttoolform},                   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
         );              );
         }          }
           my $externalform = &create_form_ul(&create_list_elements(@external));
   
           my @importdoc = ();
         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 6312  NGFFORM Line 6614  NGFFORM
 my %orderhash = (  my %orderhash = (
                 'aa' => ['Upload',$fileuploadform],                  'aa' => ['Upload',$fileuploadform],
                 'bb' => ['Import',$importpubform],                  'bb' => ['Import',$importpubform],
                 'cc' => ['Grading',$gradingform],                  'cc' => ['External',$externalform],
                   'dd' => ['Grading',$gradingform],
                 );                  );
 unless ($container eq 'page') {  unless ($container eq 'page') {
     $orderhash{'00'} = ['Newfolder',$newfolderform];      $orderhash{'00'} = ['Newfolder',$newfolderform];
     $orderhash{'dd'} = ['Collaboration',$communityform];      $orderhash{'ee'} = ['Collaboration',$communityform];
     $orderhash{'ee'} = ['Other',$specialdocumentsform];      $orderhash{'ff'} = ['Other',$specialdocumentsform];
 }  }
   
  $hadchanges=0;   $hadchanges=0;
Line 6330  unless ($container eq 'page') { Line 6633  unless ($container eq 'page') {
              $r->print('<p><span class="LC_error">'.$error.'</span></p>');               $r->print('<p><span class="LC_error">'.$error.'</span></p>');
           }            }
           if ($hadchanges) {            if ($hadchanges) {
              &mark_hash_old();                unless (&is_hash_old()) {
           }                    &mark_hash_old();
                 }
     }
   
           &changewarning($r,'');            &changewarning($r,'');
         }          }
Line 6361  unless ($container eq 'page') { Line 6666  unless ($container eq 'page') {
  <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">   <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
         <fieldset id="uploadsuppdocform" style="display: none;">          <fieldset id="uploadsuppdocform" style="display: none;">
         <legend>$lt{'upfi'}</legend>          <legend>$lt{'upfi'}</legend>
  <input type="hidden" name="active" value="ee" />   <input type="hidden" name="active" value="ee" />
  $fileupload   $fileupload
  <br />   <br />
  <br />   <br />
Line 6451  my @specialdocs = ( Line 6756  my @specialdocs = (
                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},                  {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
   
  );   );
 my @supimportdoc = (          my @supexternal = (
  {'<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:toggleExternal(\'suppext\')" />'
             =>$supextform});               =>$supextform});
         if (keys(%ltitools)) {          if (keys(%ltitools)) {
             push(@supimportdoc,              push(@supexternal,
                 {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleUpload(\'supptool\')" />'                   {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
             =>$supexttoolform});              =>$supexttoolform});
         }          }
         push(@supimportdoc,           my @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},
         );          );
Line 6467  my @supimportdoc = ( Line 6772  my @supimportdoc = (
 $supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc));  $supupdocform =  &create_form_ul(&create_list_elements(@supimportdoc));
 my %suporderhash = (  my %suporderhash = (
  '00' => ['Supnewfolder', $supnewfolderform],   '00' => ['Supnewfolder', $supnewfolderform],
                 'ee' => ['Upload',$supupdocform],                  'dd' => ['Upload',$supupdocform],
                   'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
                 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]                  'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
                 );                  );
         if ($supplementalflag) {          if ($supplementalflag) {
Line 6488  my %suporderhash = ( Line 6794  my %suporderhash = (
                    }                     }
                    &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);                     &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
                    undef($suppchanges);                     undef($suppchanges);
                }                   }
            }              }
         }          }
     } elsif ($supplementalflag) {      } elsif ($supplementalflag) {
         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,          my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
Line 6520  my %suporderhash = ( Line 6826  my %suporderhash = (
                 &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');                  &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
   }    }
  }   }
  unless ($noendpage) {    unless ($noendpage) {
      $r->print(&Apache::loncommon::end_page());       $r->print(&Apache::loncommon::end_page());
  }   }
  return OK;   return OK;
Line 6529  my %suporderhash = ( Line 6835  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 6549  sub embedded_destination { Line 6856  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 6575  sub decompression_info { Line 6886  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 6592  sub decompression_phase_one { Line 6906  sub decompression_phase_one {
         $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});          $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
     } else {      } else {
         my $file = $1;          my $file = $1;
         $output =           $output =
             &Apache::loncommon::process_decompression($docudom,$docuname,$file,              &Apache::loncommon::process_decompression($docudom,$docuname,$file,
                                                       $destination,$dir_root,                                                        $destination,$dir_root,
                                                       $hiddenelem);                                                        $hiddenelem);
Line 6687  sub generate_admin_menu { Line 7001  sub generate_admin_menu {
                                          'vc'   => 'Verify Content',                                           'vc'   => 'Verify Content',
                                          'cv'   => 'Check/Set Resource Versions',                                           'cv'   => 'Check/Set Resource Versions',
                                          'ls'   => 'List Resource Identifiers',                                           'ls'   => 'List Resource Identifiers',
                                            'ct'   => 'Display/Set Shortened URLs for Deep-linking',
                                          'imse' => 'Export contents to IMS Archive',                                           'imse' => 'Export contents to IMS Archive',
                                          'dcd'  => "Copy $crstype Content to Authoring Space",                                           'dcd'  => "Copy $crstype Content to Authoring Space",
             );              );
Line 6737  sub generate_admin_menu { Line 7052  sub generate_admin_menu {
                     icon       => 'symbs.png',                      icon       => 'symbs.png',
                     linktitle  => "List the unique identifier used for each resource instance in your $lc_crstype"                      linktitle  => "List the unique identifier used for each resource instance in your $lc_crstype"
                 },                  },
                   {   linktext   => $lt{'ct'},
                       url        => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
                       permission => 'F',
                       help       => 'Docs_Short_URLs',
                       icon       => 'shorturls.png',
                       linktitle  => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
                   },
                 ]                  ]
         });          });
     if ($canedit) {      if ($canedit) {
Line 6899  sub editing_js { Line 7221  sub editing_js {
                                           p_ctr2b => '?',                                            p_ctr2b => '?',
                                           p_ctr3a => 'Cut those',                                            p_ctr3a => 'Cut those',
                                           p_ctr3b => 'items?',                                            p_ctr3b => 'items?',
                                             setal   => 'Enter a (unique) alias',
                                             delal   => 'Are you sure you want to eliminate the alias?',
                                           rpck    => 'Enter number to pick (e.g., 3)',                                            rpck    => 'Enter number to pick (e.g., 3)',
                                           imsfile => 'You must choose an IMS package for import',                                            imsfile => 'You must choose an IMS package for import',
                                           imscms  => 'You must select which Course Management System was the source of the IMS package',                                            imscms  => 'You must select which Course Management System was the source of the IMS package',
Line 6943  sub editing_js { Line 7267  sub editing_js {
                 } else {                  } else {
                     $url = $res;                      $url = $res;
                 }                  }
                 $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='.                  $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
                              &HTML::Entities::encode($caller,'<>&"');                  if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
                       $backtourl .= '?navmap=1';
                   } else {
                       $backtourl .= '?symb='.
                                     &HTML::Entities::encode($caller,'<>&"');
                   }
                 if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {                  if ($backtourl =~ 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://})) {
                         if ($hostname ne '') {                          unless (&Apache::lonnet::uses_sts()) {
                             $backtourl = 'http://'.$hostname.$backtourl;                              if ($hostname ne '') {
                                   $backtourl = 'http://'.$hostname.$backtourl;
                               }
                               $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
                         }                          }
                         $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';  
                     }                      }
                 } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {                  } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
                     if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {                      if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
                         $backtourl = 'http://'.$hostname.$backtourl;                          unless (&Apache::lonnet::uses_sts()) {
                               if ($hostname ne '') {
                                   $backtourl = 'http://'.$hostname.$backtourl;
                               }
                               $backtourl .= (($backtourl =~ /\?/) ? '&amp;':'?').'usehttp=1';
                           }
                     }                      }
                 }                  }
                 if ($anchor ne '') {                  if ($anchor ne '') {
Line 6974  sub editing_js { Line 7310  sub editing_js {
         $backtourl = '/adm/navmaps';          $backtourl = '/adm/navmaps';
     }      }
   
     my $fieldsets = "'ext','doc'";      my $fieldsets = "'doc'";
     if ($posslti) {  
         $fieldsets .= ",'tool'";  
     }  
     unless ($main_container_page) {      unless ($main_container_page) {
         $fieldsets .=",'ims'";          $fieldsets .=",'ims'";
     }      }
       my $extfieldsets = "'ext'";
       if ($posslti) {
           $extfieldsets .= ",'tool'";
       }
     if ($supplementalflag) {      if ($supplementalflag) {
         $fieldsets = "'suppext','suppdoc'";          $fieldsets = "'suppdoc'";
           $extfieldsets = "'suppext'";
         if ($posslti) {          if ($posslti) {
             $fieldsets .= ",'supptool'";              $extfieldsets .= ",'supptool'";
         }          }
     }      }
       
     my $jsmakefunctions;      my $jsmakefunctions;
     if ($canedit) {      if ($canedit) {
         $jsmakefunctions = <<ENDNEWSCRIPT;          $jsmakefunctions = <<ENDNEWSCRIPT;
Line 7101  function changename(folderpath,index,old Line 7439  function changename(folderpath,index,old
     }      }
 }  }
   
   function setalias(folderpath,index) {
       var alias = prompt('$js_lt{"setal"}');
       if ((alias != null) && (alias != '')) {
           this.document.forms.aliasform.alias.value=alias;
           this.document.forms.aliasform.cmd.value='setalias_'+index;
           this.document.forms.aliasform.folderpath.value=folderpath;
           this.document.forms.aliasform.submit();
       }
   }
   
   function delalias(folderpath,index) {
       if (confirm('$js_lt{"delal"}')) {
           this.document.forms.aliasform.cmd.value='delalias_'+index;
           this.document.forms.aliasform.folderpath.value=folderpath;
           this.document.forms.aliasform.submit();
       }
   }
   
 ENDNEWSCRIPT  ENDNEWSCRIPT
     } else {      } else {
         $jsmakefunctions = <<ENDNEWSCRIPT;          $jsmakefunctions = <<ENDNEWSCRIPT;
Line 7145  function changename() { Line 7501  function changename() {
     alert("$js_lt{'edri'}");      alert("$js_lt{'edri'}");
 }  }
   
   function setalias() {
       alert("$js_lt{'edri'}");
   }
   
   function delalias() {
       alert("$js_lt{'edri'}");
   }
   
 function makenew() {  function makenew() {
     alert("$js_lt{'edri'}");      alert("$js_lt{'edri'}");
 }  }
Line 7182  function toggleUpload(caller) { Line 7546  function toggleUpload(caller) {
             }              }
         }          }
         document.getElementById('upload'+blocks[i]+'form').style.display=disp;          document.getElementById('upload'+blocks[i]+'form').style.display=disp;
       }
       resize_scrollbox('contentscroll','1','1');
       return;
   }
   
   function toggleExternal(caller) {
       var blocks = Array($extfieldsets);
       for (var i=0; i<blocks.length; i++) {
           var disp = 'none';
           if (caller == blocks[i]) {
               var curr = document.getElementById('external'+caller+'form').style.display;
               if (curr == 'none') {
                   disp='block';
               }
           }
           document.getElementById('external'+blocks[i]+'form').style.display=disp;
         if ((caller == 'tool') || (caller == 'supptool')) {          if ((caller == 'tool') || (caller == 'supptool')) {
             if (disp == 'block') {              if (disp == 'block') {
                 if (document.getElementById('LC_exttoolid')) {                   if (document.getElementById('LC_exttoolid')) {
                     var toolselector = document.getElementById('LC_exttoolid');                       var toolselector = document.getElementById('LC_exttoolid');
                     var suppflag = 0;                      var suppflag = 0;
                     if (caller == 'supptool') {                      if (caller == 'supptool') {
                         suppflag = 1;                          suppflag = 1;
                     }                      }
                     currForm = document.getElementById('new'+caller);                      currForm = document.getElementById('new'+caller);
                     updateExttool(toolselector,currForm,suppflag);                       updateExttool(toolselector,currForm,suppflag);
                 }                  }
             }              }
         }          }
Line 7748  function showPage(current, pageId, nav, Line 8128  function showPage(current, pageId, nav,
                 current.className = 'right';                  current.className = 'right';
             }              }
             activeTab = '';               activeTab = ''; 
               toggleExternal();
             toggleUpload();              toggleUpload();
             toggleMap();              toggleMap();
             toggleCrsRes();              toggleCrsRes();
Line 7760  function showPage(current, pageId, nav, Line 8141  function showPage(current, pageId, nav,
  currentData = document.getElementById(pageId);   currentData = document.getElementById(pageId);
  currentData.style.display = 'block';   currentData.style.display = 'block';
         activeTab = pageId;          activeTab = pageId;
           toggleExternal();
         toggleUpload();          toggleUpload();
         toggleMap();          toggleMap();
         toggleCrsRes();          toggleCrsRes();
Line 8293  sub makenewproblem { Line 8675  sub makenewproblem {
         if ($env{'form.newsubdir'}) {          if ($env{'form.newsubdir'}) {
             if ($env{'form.newsubdirname'} ne '') {              if ($env{'form.newsubdirname'} ne '') {
                 $newsubdir = $env{'form.newsubdirname'};                  $newsubdir = $env{'form.newsubdirname'};
             }                  }
         }          }
         if ($env{'form.newresourcename'}) {          if ($env{'form.newresourcename'}) {
             $filename = $env{'form.newresourcename'};              $filename = $env{'form.newresourcename'};
Line 8376  END Line 8758  END
 <subject></subject>  <subject></subject>
 <title></title>  <title></title>
 END  END
                                         close($fh);                                      close($fh);
                                 }  
                                 if ((-e $sourcerights) && (-e "$sourcerights.meta")) {  
                                     if (!-e "$docroot/res/$coursedom") {  
                                         mkdir("$docroot/res/$coursedom",0755);  
                                     }  
                                     if (!-e "$docroot/res/$coursedom/$coursenum") {  
                                         mkdir("$docroot/res/$coursedom/$coursenum",0755);  
                                     }  
                                     if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {  
                                         my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));  
                                         my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);  
                                     }  
                                 }                                  }
                             }                              }
                             if ($env{'form.newresourceadd'}) {                              if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
                                 my $template = $env{'form.template'};                                  if (!-e "$docroot/res/$coursedom") {
                                 my $source = $docroot.$redirect;                                      mkdir("$docroot/res/$coursedom",0755);
                                 my $target = $redirect;                                  }
                                 $target =~ s{^/priv/}{/res/};                                  if (!-e "$docroot/res/$coursedom/$coursenum") {
                                 $target = $docroot.$target;                                      mkdir("$docroot/res/$coursedom/$coursenum",0755);
                                 if (!-e $source) {  
                                     my $copyfrom;   
                                     if ($template) {  
                                         my %templates;  
                                         my @files = &Apache::lonhomework::get_template_list('problem');  
                                         foreach my $poss (@files) {  
                                             if (ref($poss) eq 'ARRAY') {  
                                                 if ($template eq $poss->[0]) {  
                                                     $templates{$template} = 1;  
                                                     last;  
                                                 }  
                                             }  
                                         }  
                                         if ($templates{$template}) {  
                                             $copyfrom = $template;  
                                         }  
                                     }  
                                     unless ($copyfrom) {  
                                         $copyfrom = $r->dir_config('lonIncludes').'/templates/blank.problem';  
                                     }  
                                     &File::Copy::copy($copyfrom,$source);  
                                 }                                  }
                                 if (!-e "$source.meta") {                                  if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
                                     my $cid = $coursedom.'_'.$coursenum;                                      my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
                                     my $now = time;                                      my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
                                     if (open(my $fh,">$source.meta")) {                                  }
                                         my $author=$env{'environment.firstname'}.' '.                              }
                                                    $env{'environment.middlename'}.' '.                              my $source = $docroot.$redirect;
                                                    $env{'environment.lastname'}.' '.                              if (!-e "$source.meta") {
                                                    $env{'environment.generation'};                                  my $cid = $coursedom.'_'.$coursenum;
                                         $author =~ s/\s+$//;                                  my $now = time;
                                         my $title = $env{'form.newresourcetitle'};                                  if (open(my $fh,">$source.meta")) {
                                         $title =~ s/^\s+|\s+$//g;                                      my $author=$env{'environment.firstname'}.' '.
                                         print $fh <<END;                                                 $env{'environment.middlename'}.' '.
                                                  $env{'environment.lastname'}.' '.
                                                  $env{'environment.generation'};
                                       $author =~ s/\s+$//;
                                       my $title = $env{'form.newresourcetitle'};
                                       $title =~ s/^\s+|\s+$//g;
                                       print $fh <<END;
   
 <abstract></abstract>  <abstract></abstract>
 <author>$author</author>  <author>$author</author>
Line 8456  END Line 8811  END
 <subject></subject>  <subject></subject>
 <title>$title</title>  <title>$title</title>
 END  END
                                         close($fh);                                      close($fh);
                                     }  
                                 }                                  }
                             }                              }
                         }                          }
Line 8485  END Line 8839  END
 }  }
   
 sub finishnewprob {  sub finishnewprob {
     my ($url,$path,$subdir,$newsubdir,$filename) = @_;      my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
     unless (-d $path) {      unless (-d $path) {
         unless (mkdir($path,02770)) {          unless (mkdir($path,02770)) {
             return;              return;
Line 8528  sub finishnewprob { Line 8882  sub finishnewprob {
             $redirect = "$url/$filename";              $redirect = "$url/$filename";
         }          }
     }      }
       if ((!-e $dest) && ($context ne 'upload')) {
           my $template = $env{'form.template'};
           my $copyfrom;
           if ($template ne '') {
               my %templates;
               my @files = &Apache::lonhomework::get_template_list('problem');
               foreach my $poss (@files) {
                   if (ref($poss) eq 'ARRAY') {
                       if ($template eq $poss->[0]) {
                           $templates{$template} = 1;
                           last;
                       }
                   }
               }
               if ($templates{$template}) {
                   $copyfrom = $template;
               }
           }
           if ($filename =~ /\.problem$/) {
               unless ($copyfrom) {
                   $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
               }
               &File::Copy::copy($copyfrom,$dest);
           }
       }
     return $redirect;      return $redirect;
 }  }
   
Line 8639  check on this Line 9018  check on this
   
 Verify Content  Verify Content
   
 =item devalidateversioncache() & checkversions()  =item devalidateversioncache() 
   
   =item checkversions()
   
 Check Versions  Check Versions
   

Removed from v.1.629  
changed lines
  Added in v.1.660


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