Diff for /loncom/interface/londocs.pm between versions 1.594 and 1.597

version 1.594, 2015/06/09 21:22:56 version 1.597, 2015/09/12 15:47:57
Line 1022  sub update_paste_buffer { Line 1022  sub update_paste_buffer {
         foreach my $suffix (@currpaste) {          foreach my $suffix (@currpaste) {
              my $cid = $env{'docs.markedcopy_crs_'.$suffix};               my $cid = $env{'docs.markedcopy_crs_'.$suffix};
              my $url = $env{'docs.markedcopy_url_'.$suffix};               my $url = $env{'docs.markedcopy_url_'.$suffix};
                my $mapidx = $env{'docs.markedcopy_map_'.$suffix};           
              if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&               if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
                  ($url ne '')) {                   ($url ne '')) {
                  $pasteurls{$cid.'_'.$url} = 1;                   $pasteurls{$cid.'_'.$url.'_'.$mapidx} = 1;
              }               }
         }          }
     }      }
   
 # Mark items for copying (skip any items already in user's paste buffer)  # Mark items for copying (skip any items already in user's paste buffer)
     my %addtoenv;      my %addtoenv;
                     
       my @pathitems = split(/\&/,$env{'form.folderpath'});
       my @folderconf = split(/\:/,$pathitems[-1]);
       my $ispage = $folderconf[4];
   
     foreach my $item (@possibles) {      foreach my $item (@possibles) {
         my ($orderidx,$cmd) = split(/:/,$item);          my ($orderidx,$cmd) = split(/:/,$item);
         next if ($orderidx =~ /\D/);          next if ($orderidx =~ /\D/);
         next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));          next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
           my $mapidx = $folder.':'.$orderidx.':'.$ispage;
         my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);          my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
         my %denied = &action_restrictions($coursenum,$coursedom,          my %denied = &action_restrictions($coursenum,$coursedom,
                                           &LONCAPA::map::qtescape($url),                                            &LONCAPA::map::qtescape($url),
                                           $env{'form.folderpath'},\%curr_groups);                                            $env{'form.folderpath'},\%curr_groups);
         next if ($denied{'copy'});          next if ($denied{'copy'});
         $url=~s{http(:|:)//https(:|:)//}{https$2//};          $url=~s{http(:|:)//https(:|:)//}{https$2//};
         next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));          next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
         my ($suffix,$errortxt,$locknotfreed) =          my ($suffix,$errortxt,$locknotfreed) =
             &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');              &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
         if ($suffix ne '') {          if ($suffix ne '') {
Line 1061  sub update_paste_buffer { Line 1067  sub update_paste_buffer {
         $addtoenv{'docs.markedcopy_url_'.$suffix}   = $url,          $addtoenv{'docs.markedcopy_url_'.$suffix}   = $url,
         $addtoenv{'docs.markedcopy_cmd_'.$suffix}   = $cmd,          $addtoenv{'docs.markedcopy_cmd_'.$suffix}   = $cmd,
         $addtoenv{'docs.markedcopy_crs_'.$suffix}   = $env{'request.course.id'};          $addtoenv{'docs.markedcopy_crs_'.$suffix}   = $env{'request.course.id'};
            $addtoenv{'docs.markedcopy_map_'.$suffix}   = $mapidx;
         if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {          if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
             my $prefix = $1;              my $prefix = $1;
             my $subdir =$2;              my $subdir =$2;
Line 1139  sub print_paste_buffer { Line 1145  sub print_paste_buffer {
         next if ($suffix =~ /\D/);          next if ($suffix =~ /\D/);
         my $cid = $env{'docs.markedcopy_crs_'.$suffix};          my $cid = $env{'docs.markedcopy_crs_'.$suffix};
         my $url = $env{'docs.markedcopy_url_'.$suffix};          my $url = $env{'docs.markedcopy_url_'.$suffix};
           my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
         if (($cid =~ /^$match_domain\_$match_courseid$/) &&          if (($cid =~ /^$match_domain\_$match_courseid$/) &&
             ($url ne '')) {              ($url ne '')) {
             $clipboardcount ++;              $clipboardcount ++;
Line 1164  sub print_paste_buffer { Line 1171  sub print_paste_buffer {
                     if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {                      if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
                         $othercourse = 1;                          $othercourse = 1;
                         if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {                          if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
                             if ($canpaste) {                              $othercrs = '<br />'.&mt('(from another course)');
                                 $othercrs = '<br />'.&mt('(from another course)');  
                             }  
                         } else {                          } else {
                             $canpaste = 0;                              $canpaste = 0;
                             $nopaste = &mt('Paste from another course unavailable.');                               $nopaste = &mt('Paste from another course unavailable.'); 
Line 1180  sub print_paste_buffer { Line 1185  sub print_paste_buffer {
                         }                          }
                         $is_uploaded_map = 1;                          $is_uploaded_map = 1;
                     }                      }
                   } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
                            ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg)$})) {
                       if ($cid ne $env{'request.course.id'}) {
                           my ($srcdom,$srcnum) = split(/_/,$cid);
                           if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
                               $othercrs = '<br />'.&mt('(from another course)');
                           } else {
                               $canpaste = 0;
                               $nopaste = &mt('Paste from another course unavailable.');
                           }       
                       }
                 }                  }
             }                  if ($canpaste) {
             if ($canpaste) {                      push(@pasteable,$suffix);
                push(@pasteable,$suffix);                  }  
             }              }
             my $buffer;              my $buffer;
             if ($is_external) {              if ($is_external) {
Line 1469  sub do_paste_from_buffer { Line 1485  sub do_paste_from_buffer {
     }      }
   
     my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,      my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
         %prefixchg,%srcdom,%srcnum,%marktomove,$save_err,$lockerrors,$allresult);          %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
   
     foreach my $suffix (@topaste) {      foreach my $suffix (@topaste) {
         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});          my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
           my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
           my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix}); 
 # Supplemental content may only include certain types of content  # Supplemental content may only include certain types of content
 # Early out if pasted content is not supported in Supplemental area  # Early out if pasted content is not supported in Supplemental area
         if ($folder =~ /^supplemental/) {          if ($folder =~ /^supplemental/) {
Line 1494  sub do_paste_from_buffer { Line 1512  sub do_paste_from_buffer {
             }              }
             $srcdom{$suffix} = $srcd;              $srcdom{$suffix} = $srcd;
             $srcnum{$suffix} = $srcn;              $srcnum{$suffix} = $srcn;
           } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
                    ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$})) {
               my ($srcd,$srcn) = split(/_/,$cid);
   # When paste buffer was populated using an active role in a different course
   # check for mdc privilege in the course from which the resource was pasted
               if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
                   unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
                       $notincrs{$suffix} = 1;
                       next;
                   }
               }
               $srcdom{$suffix} = $srcd;
               $srcnum{$suffix} = $srcn;
         }          }
           $srcmapidx{$suffix} = $mapidx;
         push(@dopaste,$suffix);          push(@dopaste,$suffix);
         if ($url=~/\.(page|sequence)$/) {          if ($url=~/\.(page|sequence)$/) {
             $is_map{$suffix} = 1;               $is_map{$suffix} = 1; 
Line 1505  sub do_paste_from_buffer { Line 1536  sub do_paste_from_buffer {
             my $oldprefix = $1;              my $oldprefix = $1;
 # When pasting content from Main Content to Supplemental Content and vice versa   # When pasting content from Main Content to Supplemental Content and vice versa 
 # URLs will contain different paths (which depend on whether pasted item is  # URLs will contain different paths (which depend on whether pasted item is
 # a folder/page or a document.     # a folder/page or a document).
             if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {              if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
                 $prefixchg{$suffix} = 'docstosupp';                  $prefixchg{$suffix} = 'docstosupp';
             } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {              } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
Line 1587  sub do_paste_from_buffer { Line 1618  sub do_paste_from_buffer {
 # Maps need to be copied first  # Maps need to be copied first
         my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,          my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
             %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,              %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
             %newurls,%tomove);              %newurls,%tomove,%resdatacopy);
         if (ref($marktomove{$suffix}) eq 'ARRAY') {          if (ref($marktomove{$suffix}) eq 'ARRAY') {
             map { $tomove{$_} = 1; } @{$marktomove{$suffix}};              map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
         }          }
         my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});          my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
         my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});          my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
           my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix}); 
         my $oldurl = $url;          my $oldurl = $url;
         if ($is_map{$suffix}) {          if ($is_map{$suffix}) {
 # If pasting a map, check if map contains other maps  # If pasting a map, check if map contains other maps
Line 1628  sub do_paste_from_buffer { Line 1660  sub do_paste_from_buffer {
                                               \%retitles,\%copies,\%dbcopies,                                                \%retitles,\%copies,\%dbcopies,
                                               \%zombies,\%params,\%mapmoves,                                                \%zombies,\%params,\%mapmoves,
                                               \%mapchanges,\%tomove,\%newsubdir,                                                \%mapchanges,\%tomove,\%newsubdir,
                                               \%newurls)) {                                                \%newurls,\%resdatacopy)) {
                         $mapmoves{$url} = 1;                          $mapmoves{$url} = 1;
                     }                      }
                     $url = $newurl;                      $url = $newurl;
Line 1637  sub do_paste_from_buffer { Line 1669  sub do_paste_from_buffer {
                                       $coursenum,$srcdom{$suffix},$srcnum{$suffix},                                        $coursenum,$srcdom{$suffix},$srcnum{$suffix},
                                       $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,                                        $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
                                       \%zombies,\%params,\%mapmoves,\%mapchanges,                                        \%zombies,\%params,\%mapmoves,\%mapchanges,
                                       \%tomove,\%newsubdir,\%newurls);                                         \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
                 }                  }
             } elsif ($url=~m {^/res/}) {              } elsif ($url=~m {^/res/}) {
 # published map can only exists once, so remove from paste buffer when done  # published map can only exist once, so remove from paste buffer when done
                 push(@toclear,$suffix);                  push(@toclear,$suffix);
 # if pasting published map (main content area only) check map not already in course  # if pasting published map (main content area only) check map not already in course
                 if ($folder =~ /^default/) {                  if ($folder =~ /^default/) {
Line 1653  sub do_paste_from_buffer { Line 1685  sub do_paste_from_buffer {
         }          }
         if ($url=~ m{/(bulletinboard|smppg)$}) {          if ($url=~ m{/(bulletinboard|smppg)$}) {
             my $prefix = $1;              my $prefix = $1;
               my $fromothercrs; 
             #need to copy the db contents to a new one, unless this is a move.              #need to copy the db contents to a new one, unless this is a move.
             my %info = (              my %info = (
                          src  => $url,                           src  => $url,
                          cdom => $coursedom,                           cdom => $coursedom,
                          cnum => $coursenum,                           cnum => $coursenum,
             );                         );
             unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {              if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
                   unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
                       $fromothercrs = 1;
                       $info{'cdom'} = $srcdom{$suffix};
                       $info{'cnum'} = $srcnum{$suffix};
                   }
               }
               unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
                 my (%lockerr,$msg);                   my (%lockerr,$msg); 
                 my ($newurl,$result,$errtext) =                  my ($newurl,$result,$errtext) =
                     &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);                      &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
Line 1735  sub do_paste_from_buffer { Line 1775  sub do_paste_from_buffer {
                         }                          }
                     }                      }
                 }                  }
               } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                   my $template = $1;
                   if ($newidx) {
                       &copy_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
                                             $coursedom,$coursenum,$template,$newidx,"$folder.$container");
                   }
             }              }
             $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).              $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
                                               ':'.$ext.':normal:res';                                                ':'.$ext.':normal:res';
Line 1748  sub do_paste_from_buffer { Line 1794  sub do_paste_from_buffer {
             }              }
         }          }
   
 # Apply any changes to maps, or copy dependencies for uploaded HTML pages   # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
   # resourcedata for simpleproblems copied from another course 
         unless ($allresult eq 'fail') {          unless ($allresult eq 'fail') {
             my %updated = (              my %updated = (
                             rewrites      => \%rewrites,                              rewrites      => \%rewrites,
Line 1756  sub do_paste_from_buffer { Line 1803  sub do_paste_from_buffer {
                             removefrommap => \%removefrommap,                              removefrommap => \%removefrommap,
                             removeparam   => \%removeparam,                              removeparam   => \%removeparam,
                             dbcopies      => \%dbcopies,                              dbcopies      => \%dbcopies,
                               resdatacopy   => \%resdatacopy,
                             retitles      => \%retitles,                              retitles      => \%retitles,
                           );                            );
             my %info = (              my %info = (
Line 1920  sub get_newmap_url { Line 1968  sub get_newmap_url {
 sub dbcopy {  sub dbcopy {
     my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;      my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
     my ($url,$result,$errtext);      my ($url,$result,$errtext);
     $url = $dbref->{'src'};  
     if (ref($dbref) eq 'HASH') {      if (ref($dbref) eq 'HASH') {
           $url = $dbref->{'src'};
         if ($url =~ m{/(smppg|bulletinboard)$}) {          if ($url =~ m{/(smppg|bulletinboard)$}) {
             my $prefix = $1;              my $prefix = $1;
             if (($dbref->{'cdom'} =~ /^$match_domain$/) &&               if (($dbref->{'cdom'} =~ /^$match_domain$/) && 
Line 1959  sub dbcopy { Line 2007  sub dbcopy {
                         my $photo = $contents{'uploaded.photourl'};                          my $photo = $contents{'uploaded.photourl'};
                         my ($subdir,$fname) =                          my ($subdir,$fname) =
                             ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});                              ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
                         my $newphoto;                           my $newphoto;
                         if ($fname ne '') {                          if ($fname ne '') {
                             my $content = &Apache::lonnet::getfile($photo);                              my $content = &Apache::lonnet::getfile($photo);
                             unless ($content eq '-1') {                              unless ($content eq '-1') {
Line 2012  sub dbcopy { Line 2060  sub dbcopy {
     return ($url,$result,$errtext);      return ($url,$result,$errtext);
 }  }
   
   sub copy_templated_files {
       my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
       my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
       my $srccontainer = 'sequence';
       if ($srcwaspage) {
           $srccontainer = 'page';
       }
       my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
                     '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
       my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
       my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
       my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
                     $template.'.problem';
       my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
       if ($template eq 'simpleproblem') {
           $srcprefix .= '.0.';
           my $weightprefix = $newprefix;
           $newprefix .= '.0.';
           my @simpleprobqtypes = qw(radio option string essay numerical);
           my $qtype=$srcparms{$srcprefix.'questiontype'};
           if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
               my %newdata;
               foreach my $type (@simpleprobqtypes) {
                   if ($type eq $qtype) {
                       $newdata{"$weightprefix.$type.weight"}=1;
                   } else {
                       $newdata{"$weightprefix.$type.weight"}=0;
                   }
               }
               $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
               $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
               $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
               if ($qtype eq 'numerical') {
                   $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
                   $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
                   $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
                   $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
               } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   unless (defined($maxfoils)) { $maxfoils=10; }
                       unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                           if ($maxfoils<=0) { $maxfoils=10; }
                               my $randomize=$srcparms{$srcprefix.'randomize'};
                               unless (defined($randomize)) { $randomize='yes'; }
                               unless ($randomize eq 'no') { $randomize='yes'; }
                               $newdata{$newprefix.'maxfoils'} = $maxfoils;
                               $newdata{$newprefix.'randomize'} = $randomize;
                               if ($qtype eq 'option') {
                                   $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                               }
                               for (my $i=1; $i<=10; $i++) {
                                   $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                                   $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                                   $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                               }
   
               } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
                   my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
                   unless (defined($maxfoils)) { $maxfoils=10; }
                   unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
                   if ($maxfoils<=0) { $maxfoils=10; }
                   my $randomize=$srcparms{$srcprefix.'randomize'};
                   unless (defined($randomize)) { $randomize='yes'; }
                   unless ($randomize eq 'no') { $randomize='yes'; }
                   $newdata{$newprefix.'maxfoils'} = $maxfoils;
                   $newdata{$newprefix.'randomize'} = $randomize;
                   if ($qtype eq 'option') {
                       $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
                   }
                   for (my $i=1; $i<=10; $i++) {
                       $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
                       $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
                       $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
                   }
               } elsif ($qtype eq 'string') {
                   $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
                   $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
               }
               if (keys(%newdata)) {
                   my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
                                                      $coursenum);
                   if ($putres eq 'ok') {
                       &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
                   }
               }
           }
       }
   }
   
 sub uniqueness_check {  sub uniqueness_check {
     my ($newurl) = @_;      my ($newurl) = @_;
     my $unique = 1;      my $unique = 1;
Line 2077  sub contained_map_check { Line 2214  sub contained_map_check {
 sub url_paste_fixups {  sub url_paste_fixups {
     my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,      my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
         $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,          $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
         $mapchanges,$tomove,$newsubdir,$newurls) = @_;          $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
     my $checktitle;      my $checktitle;
     if (($prefixchg) &&      if (($prefixchg) &&
         ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {          ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
Line 2126  sub url_paste_fixups { Line 2263  sub url_paste_fixups {
                                           $srcdom,$srcnum,$allmaps,$rewrites,                                            $srcdom,$srcnum,$allmaps,$rewrites,
                                           $retitles,$copies,$dbcopies,$zombies,                                            $retitles,$copies,$dbcopies,$zombies,
                                           $params,$mapmoves,$mapchanges,$tomove,                                            $params,$mapmoves,$mapchanges,$tomove,
                                           $newsubdir,$newurls);                                            $newsubdir,$newurls,$resdatacopy);
                         next;                          next;
                     } else {                      } else {
                         ($newurl,my $error) =                          ($newurl,my $error) =
Line 2150  sub url_paste_fixups { Line 2287  sub url_paste_fixups {
                                                   $cnum,$srcdom,$srcnum,$allmaps,                                                    $cnum,$srcdom,$srcnum,$allmaps,
                                                   $rewrites,$retitles,$copies,$dbcopies,                                                    $rewrites,$retitles,$copies,$dbcopies,
                                                   $zombies,$params,$mapmoves,$mapchanges,                                                    $zombies,$params,$mapmoves,$mapchanges,
                                                   $tomove,$newsubdir,$newurls)) {                                                    $tomove,$newsubdir,$newurls,$resdatacopy)) {
                             $mapmoves->{$ressrc} = 1;                              $mapmoves->{$ressrc} = 1;
                         }                          }
                         $changed = 1;                          $changed = 1;
Line 2179  sub url_paste_fixups { Line 2316  sub url_paste_fixups {
                     $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;                      $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
                     $changed = 1;                      $changed = 1;
                 }                  }
               } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
                   if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
                       $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
                       $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
                       $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
                   }
             } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {              } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
                 next if ($skip);                  next if ($skip);
                 my $srcdom = $1;                  my $srcdom = $1;
Line 2210  sub apply_fixups { Line 2353  sub apply_fixups {
         $oldurl,$url,$caller) = @_;          $oldurl,$url,$caller) = @_;
     my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,      my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
         %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,          %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
         %lockerrors,$lockmsg);          %resdatacopy,%lockerrors,$lockmsg);
     if (ref($updated) eq 'HASH') {      if (ref($updated) eq 'HASH') {
         if (ref($updated->{'rewrites'}) eq 'HASH') {          if (ref($updated->{'rewrites'}) eq 'HASH') {
             %rewrites = %{$updated->{'rewrites'}};              %rewrites = %{$updated->{'rewrites'}};
Line 2230  sub apply_fixups { Line 2373  sub apply_fixups {
         if (ref($updated->{'retitles'}) eq 'HASH') {          if (ref($updated->{'retitles'}) eq 'HASH') {
             %retitles = %{$updated->{'retitles'}};              %retitles = %{$updated->{'retitles'}};
         }          }
           if (ref($updated->{'resdatacopy'}) eq 'HASH') {
               %resdatacopy = %{$updated->{'resdatacopy'}};
           }
     }      }
     if (ref($info) eq 'HASH') {      if (ref($info) eq 'HASH') {
         if (ref($info->{'newsubdir'}) eq 'HASH') {          if (ref($info->{'newsubdir'}) eq 'HASH') {
Line 2380  sub apply_fixups { Line 2526  sub apply_fixups {
                     }                      }
                 }                  }
             }              }
               if (ref($resdatacopy{$key}) eq 'HASH') {
                   if ($newsubdir{$key}) {
   
                   }
                   foreach my $idx (keys(%{$resdatacopy{$key}})) {
                       if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
                           my $srcurl = $resdatacopy{$key}{$idx}{'src'};
                           if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
                               my $template = $1;
                               if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
                                   ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
                                   my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
                                   my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
                                   my ($newmapname) = ($key =~ m{/([^/]+)$});
                                   my ($srcfolder,$srccontainer) = split(/\./,$newmapname);
                                   my $srcmapinfo = $srcfolder.':'.$idx;
                                   if ($srccontainer eq 'page') {
                                       $srcmapinfo .= ':1';
                                   }
                                   if ($newsubdir{$key}) {
                                       $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
                                   }
                                   &copy_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
                                                         $cnum,$template,$idx,$newmapname);
                               }
                           }
                       }
                   }
               }
             if (ref($params{$key}) eq 'HASH') {              if (ref($params{$key}) eq 'HASH') {
                 %currparam = %{$params{$key}};                  %currparam = %{$params{$key}};
             }              }
Line 3801  sub action_restrictions { Line 3976  sub action_restrictions {
     if ($url=~ m{^/res/.+\.(page|sequence)$}) {      if ($url=~ m{^/res/.+\.(page|sequence)$}) {
         # no copy for published maps          # no copy for published maps
         $denied{'copy'} = 1;          $denied{'copy'} = 1;
     } elsif ($url=~m{^/res/lib/templates/}) {      } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
        $denied{'copy'} = 1;          unless ($1 eq 'simpleproblem') {
        $denied{'cut'} = 1;              $denied{'copy'} = 1;
           }
           $denied{'cut'} = 1;
     } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {      } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
         if ($folderpath =~ /^default&[^\&]+$/) {          if ($folderpath =~ /^default&[^\&]+$/) {
             if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {              if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
Line 4769  sub handler { Line 4946  sub handler {
               .'// <![CDATA['."\n"                .'// <![CDATA['."\n"
               .$script."\n"                .$script."\n"
               .'// ]]>'."\n"                .'// ]]>'."\n"
               .'</script>'."\n";                .'</script>'."\n"
                 .'<script type="text/javascript" 
                   src="/res/adm/includes/file_upload.js"></script>'."\n";
   
     # Breadcrumbs      # Breadcrumbs
     &Apache::lonhtmlcommon::clear_breadcrumbs();      &Apache::lonhtmlcommon::clear_breadcrumbs();
Line 4899  sub handler { Line 5078  sub handler {
                 'webctce4' => 'WebCT 4 Campus Edition',                  'webctce4' => 'WebCT 4 Campus Edition',
         );          );
 # -----------------------------------------------------------------------------  # -----------------------------------------------------------------------------
   
       # Calculate free quota space for a user or course. A javascript function checks
       # file size to determine if upload should be allowed.
       my $quotatype = 'unofficial';
       if ($crstype eq 'Community') {
           $quotatype = 'community';    
       } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
           $quotatype = 'official';
       } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
           $quotatype = 'textbook';
       }
       my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
                        'course',$quotatype); # expressed in MB
       my $current_disk_usage = 0;
       foreach my $subdir ('docs','supplemental') {
           $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
                                  "userfiles/$subdir",1); # expressed in kB
       }
       my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
   
  my $fileupload=(<<FIUP);   my $fileupload=(<<FIUP);
  $lt{'file'}:<br />   $lt{'file'}:<br />
  <input type="file" name="uploaddoc" size="40" />   <input type="file" name="uploaddoc" class="flUpload" size="40" />
       <input type="hidden" id="free_space" value="$free_space" />
 FIUP  FIUP
   
  my $checkbox=(<<CHBO);   my $checkbox=(<<CHBO);
Line 4948  IMSFORM Line 5148  IMSFORM
         <fieldset id="uploaddocform" style="display: none;">          <fieldset id="uploaddocform" style="display: none;">
         <legend>$lt{'upfi'}</legend>          <legend>$lt{'upfi'}</legend>
  <input type="hidden" name="active" value="aa" />   <input type="hidden" name="active" value="aa" />
  $fileupload      $fileupload
  <br />   <br />
  $lt{'title'}:<br />   $lt{'title'}:<br />
  <input type="text" size="60" name="comment" />   <input type="text" size="60" name="comment" />

Removed from v.1.594  
changed lines
  Added in v.1.597


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