Diff for /loncom/interface/londocs.pm between versions 1.558 and 1.568

version 1.558, 2013/08/13 15:38:35 version 1.568, 2013/11/13 01:40:07
Line 41  use Apache::lonclonecourse; Line 41  use Apache::lonclonecourse;
 use Apache::lonnavmaps;  use Apache::lonnavmaps;
 use Apache::lonnavdisplay();  use Apache::lonnavdisplay();
 use Apache::lonextresedit();  use Apache::lonextresedit();
   use Apache::lontemplate();
   use Apache::lonsimplepage();
 use HTML::Entities;  use HTML::Entities;
 use HTML::TokeParser;  use HTML::TokeParser;
 use GDBM_File;  use GDBM_File;
Line 141  sub clean { Line 143  sub clean {
 sub dumpcourse {  sub dumpcourse {
     my ($r) = @_;      my ($r) = @_;
     my $crstype = &Apache::loncommon::course_type();      my $crstype = &Apache::loncommon::course_type();
     $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Content to Authoring Space')."\n".      my ($starthash,$js);
               &Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' Content to Authoring Space')."\n");      unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
           $js = <<"ENDJS";
   <script type="text/javascript">
   // <![CDATA[
   
   function hide_searching() {
       if (document.getElementById('searching')) {
           document.getElementById('searching').style.display = 'none';
       }
       return;
   }
   
   // ]]>
   </script>
   ENDJS
           $starthash = {
                            add_entries => {'onload' => "hide_searching();"},
                        };
       }
       $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
                 &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
     $r->print(&startContentScreen('tools'));      $r->print(&startContentScreen('tools'));
     my ($home,$other,%outhash)=&authorhosts();      my ($home,$other,%outhash)=&authorhosts();
     unless ($home) {      unless ($home) {
Line 161  sub dumpcourse { Line 183  sub dumpcourse {
  $r->print('<h3>'.&mt('Copying Files').'</h3>');   $r->print('<h3>'.&mt('Copying Files').'</h3>');
  my $title=$env{'form.authorfolder'};   my $title=$env{'form.authorfolder'};
  $title=&clean($title);   $title=&clean($title);
  my %replacehash=();          my ($navmap,$errormsg) =
  foreach my $key (keys(%env)) {              &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
     if ($key=~/^form\.namefor\_(.+)/) {          my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  $replacehash{$1}=$env{$key};          my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     }          my (%maps,%resources,%titles);
           if (!ref($navmap)) {
               $r->print($errormsg.
                         &endContentScreen());
               return '';
           } else {
               &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
                                                                      'dumpdocs',$cdom,$cnum);
  }   }
           my @todump = &Apache::loncommon::get_env_multiple('form.archive');
           my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
               %newcontent,%has_simpleprobs);
           foreach my $item (sort {$a <=> $b} (@todump)) {
               my $name = $env{'form.namefor_'.$item};
               if ($resources{$item}) {
                   my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
                   if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
                       $tocopy{$1} = $name;
                       $display{$item} = $1;
                       $lookup{$1} = $item; 
                   } elsif ($res eq 'lib/templates/simpleproblem.problem') {
                       $simpleproblems{$item} = {
                                                   symb => $resources{$item},
                                                   name => $name,
                                                };
                       $display{$item} = 'simpleproblem_'.$name;
                       if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
                           $has_simpleprobs{$1}{$id} = $item;
                       }
                   } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
                       my $marker = $1;
                       my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
                       $simplepages{$item} = {
                                               res    => $res,
                                               title  => $titles{$item},
                                               db     => $db_name,
                                               marker => $marker,
                                               symb   => $resources{$item},
                                               name   => $name,
                                             };
                       $display{$item} = '/'.$res;
                   }
               } elsif ($maps{$item}) {
                   if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
                       $tocopy{$1} = $name;
                       $display{$item} = $1;
                       $lookup{$1} = $item;
                   }
               } else {
                   next;
               }
           }
  my $crs='/uploaded/'.$env{'request.course.id'}.'/';   my $crs='/uploaded/'.$env{'request.course.id'}.'/';
  $crs=~s/\_/\//g;   $crs=~s/\_/\//g;
  foreach my $item (keys(%replacehash)) {          my $mm = new File::MMagic;
     my $newfilename=$title.'/'.$replacehash{$item};          my $prefix = "/uploaded/$cdom/$cnum/";
     $newfilename=~s/\.(\w+)$//;          %replacehash = %tocopy;
     my $ext=$1;          foreach my $item (sort(keys(%simpleproblems))) {
     $newfilename=&clean($newfilename);              my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
     $newfilename.='.'.$ext;              $newcontent{$display{$item}} = $content;
     my @dirs=split(/\//,$newfilename);          }
     my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";          my $gateway = Apache::lonhtmlgateway->new('web');
     my $makepath=$path;          foreach my $item (sort(keys(%simplepages))) {
     my $fail=0;              if (ref($simplepages{$item}) eq 'HASH') {
     for (my $i=0;$i<$#dirs;$i++) {                  my $pagetitle = $simplepages{$item}{'title'};
  $makepath.='/'.$dirs[$i];                  my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
  unless (-e $makepath) {                  my %contents;
     unless(mkdir($makepath,0777)) { $fail=1; }                  foreach my $field (keys(%fields)) {
  }                      if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
     }                          my $name = $1;
     $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');                          my $msg = $fields{$field};
     if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {                          if ($name eq 'webreferences') {
  if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {                              if ($msg =~ m{^https?://}) {
     print $fh &Apache::lonclonecourse::rewritefile(                                  $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
          &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),                              }
      (%replacehash,$crs => '')                          } else {
     );                              $msg = &Encode::decode('utf8',$msg);
  } else {                              $msg = $gateway->process_outgoing_html($msg,1);
     print $fh                              $contents{$name} = $msg;
          &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);                          }
        }                      } elsif ($field eq 'uploaded.photourl') {
  $fh->close();                          my $marker = $simplepages{$item}{marker};
     } else {                          if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
  $fail=1;                              my $filepath = $1;
     }                              my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
     if ($fail) {                              if ($fname ne '') {
  $r->print('<span class="LC_error">'.&mt('fail').'</span>');                                  $fname=~s/\.(\w+)$//;
     } else {                                  my $ext=$1;
  $r->print('<span class="LC_success">'.&mt('ok').'</span>');                                  $fname = &clean($fname);
     }                                  $fname.='.'.$ext;
  }                                  $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
                                   $replacehash{$filepath} = $relpath.$fname;
                                   $deps{$item}{$filepath} = 1;
                               }
                           }
                       }
                   }
                   $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
                   $lookup{'/'.$simplepages{$item}{'res'}} = $item;
                   my $content = '
   <html>
   <head>
   <title>'.$pagetitle.'</title>
   </head>
   <body bgcolor="#ffffff">';
                   if ($contents{title}) {
                       $content .= "\n".'<h2>'.$contents{title}.'</h2>';
                   }
                   if ($contents{image}) {
                       $content .= "\n".$contents{image};
                   }
                   if ($contents{content}) {
                       $content .= '
   <div class="LC_Box">
   <h4 class="LC_hcell">Content</h4>'.
   $contents{content}.'
   </div>';
                   }
                   if ($contents{webreferences}) {
                       $content .= ' 
   <div class="LC_Box">
   <h4 class="LC_hcell">Web References</h4>'.
   $contents{webreferences}.'
   </div>';
                   }
                   $content .= '
   </body>
   </html>
   ';
                   $newcontent{'/'.$simplepages{$item}{res}} = $content; 
               }
           }
    foreach my $item (keys(%tocopy)) {
               unless ($item=~/\.(sequence|page)$/) {
                   my $currurlpath = $prefix.$item;
                   my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
                   &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
               }
           }
           foreach my $num (sort {$a <=> $b} (@todump)) {
               my $src = $display{$num};
               next if ($src eq '');
               my @needcopy = ();
               if ($replacehash{$src}) {
                   push(@needcopy,$src);
                   if (ref($deps{$num}) eq 'HASH') {
                       foreach my $dep (sort(keys(%{$deps{$num}}))) {
                           if ($replacehash{$dep}) {
                               push(@needcopy,$dep);
                           }
                       }
                   }
               } elsif ($src =~ /^simpleproblem_/) {
                   push(@needcopy,$src);
               }
               next if (@needcopy == 0);
               my ($result,$depresult);
               for (my $i=0; $i<@needcopy; $i++) {
                   my $item = $needcopy[$i];
                   my $newfilename;
                   if ($simpleproblems{$num}) {
                       $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
                   } else {
               $newfilename=$title.'/'.$replacehash{$item};
                   }
           $newfilename=~s/\.(\w+)$//;
           my $ext=$1;
           $newfilename=&clean($newfilename);
           $newfilename.='.'.$ext;
                   my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$}); 
                   if ($newrelpath ne $replacehash{$item}) {
                       $replacehash{$item} = $newrelpath;
                   }
           my @dirs=split(/\//,$newfilename);
           my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
           my $makepath=$path;
           my $fail;
                   my $origin;
           for (my $i=0;$i<$#dirs;$i++) {
       $makepath.='/'.$dirs[$i];
       unless (-e $makepath) {
           unless(mkdir($makepath,0755)) { 
                               $fail = &mt('Directory creation failed.');
                           }
       }
           }
                   if ($i == 0) {
               $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
                   } else {
                       $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
                                     '<span class="LC_fontsize_small" style="font-weight: bold;">'.
                                     &mt('(dependency)').'</span>: ';
                   }
                   if (-e $path.'/'.$newfilename) {
                       $fail = &mt('Destination already exists -- not overwriting.'); 
           } else {
                       if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
                           if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
                               ($item =~ /^simpleproblem_/)) {
                               print $fh $newcontent{$item};
                           } else {
                               my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
                               if (-e $fileloc) {
                                   if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
                                       if ((($1 eq 'sequence') || ($1 eq 'page')) &&
                                           (ref($has_simpleprobs{$item}) eq 'HASH')) {
                                           my %changes = %{$has_simpleprobs{$item}};
                                           my $content = &Apache::lonclonecourse::rewritefile(
                        &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
                                                         (%replacehash,$crs => '')
                                                                                             );
                                           my $updatedcontent = '';
                                           my $parser = HTML::TokeParser->new(\$content);
                                           $parser->attr_encoded(1);
                                           while (my $token = $parser->get_token) {
                                               if ($token->[0] eq 'S') {
                                                   if (($token->[1] eq 'resource') &&
                                                       ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') && 
                                                       ($changes{$token->[2]->{'id'}})) {
                                                       my $id = $token->[2]->{'id'};
                                                       $updatedcontent .= '<'.$token->[1];
                                                       foreach my $attrib (@{$token->[3]}) {
                                                           next unless ($attrib =~ /^(src|type|title|id)$/);
                                                           if ($attrib eq 'src') {
                                                               my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/); 
                                                               if ($file) {
                                                                   $updatedcontent .= ' '.$attrib.'="'.$file.'"';
                                                               } else {
                                                                   $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"'; 
                                                               }
                                                           } else {
                                                               $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
                                                           }
                                                       }
                                                       $updatedcontent .= ' />'."\n";
                                                   } else {
                                                       $updatedcontent .= $token->[4]."\n";
                                                   }
                                                } else {
                                                    $updatedcontent .= $token->[2];
                                                }
                                            }
                                            print $fh $updatedcontent;
                                       } else {  
                           print $fh &Apache::lonclonecourse::rewritefile(
                        &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
                                         (%replacehash,$crs => '')
                                 );
                                       }
                                   } else {
                       print $fh
                                           &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
                   }
                               } else {
                                   $fail = &mt('Source does not exist.');  
                               }
                           }
                           $fh->close();
               } else {
           $fail = &mt('Could not write to destination.');
                       }
           }
                   my $text;
           if ($fail) {
                       $text = '<span class="LC_error">'.&mt('fail').('&nbsp;'x3).$fail.'</span>';
           } else {
                       $text = '<span class="LC_success">'.&mt('ok').'</span>';
                   }
                   if ($i == 0) {
                       $result .= $text;
                   } else {
                       $depresult .= $text.'</li>';
           }
               }
               $r->print($result);
               if ($depresult) {
                   $r->print('<ul>'.$depresult.'</ul>');
               }
           }
     } else {      } else {
         $r->print(&mt('Searching ...').'<br />');          my ($navmap,$errormsg) =
         $r->rflush();              &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
 # Input form          if (!ref($navmap)) {
         $r->print('<form name="dumpdoc" action="" method="post">'."\n");              $r->print($errormsg);
  unless ($home==1) {          } else {
     $r->print('<div class="LC_left_float">'.              $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
       '<fieldset><legend>'.              $r->rflush();
                       &mt('Select the Authoring Space').              my ($preamble,$formname);
                       '</legend><select name="authorspace">');              $formname = 'dumpdoc';
  }      unless ($home==1) {
  foreach my $key (sort(keys(%outhash))) {          $preamble = '<div class="LC_left_float">'.
     if ($key=~/^home_(.+)$/) {              '<fieldset><legend>'.
                               &mt('Select the Authoring Space').
                               '</legend><select name="authorspace">';
       }
               my @orderspaces = ();
       foreach my $key (sort(keys(%outhash))) {
                   if ($key=~/^home_(.+)$/) {
                       if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
                           unshift(@orderspaces,$1);
                       } else {
                           push(@orderspaces,$1);
                       }
                   } 
               }
               foreach my $user (@orderspaces) {
  if ($home==1) {   if ($home==1) {
     $r->print(      $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
   '<input type="hidden" name="authorspace" value="'.$1.'" />');  
  } else {   } else {
     $r->print('<option value="'.$1.'">'.$1.' - '.      $preamble .= '<option value="'.$user.'">'.$user.' - '.
       &Apache::loncommon::plainname(split(/\:/,$1)).'</option>');           &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
  }          }
     }      }
  }      unless ($home==1) {
  unless ($home==1) {          $preamble .= '</select></fieldset></div>'."\n";
     $r->print('</select></fieldset></div>'."\n");  
  }  
  my $title=$origcrsdata{'description'};  
  $title=~s/[\/\s]+/\_/gs;  
  $title=&clean($title);  
  $r->print('<div class="LC_left_float">'.  
                   '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.  
                   '<input type="text" size="50" name="authorfolder" value="'.  
                   $title.'" />'.  
                   '</fieldset></div><br clear="all" />'."\n");  
  &tiehash();  
  $r->print('<h4>'.&mt('Filenames in Authoring Space').'</h4>'  
                  .&Apache::loncommon::start_data_table()  
                  .&Apache::loncommon::start_data_table_header_row()  
                  .'<th>'.&mt('Internal Filename').'</th>'  
                  .'<th>'.&mt('Title').'</th>'  
                  .'<th>'.&mt('Save as ...').'</th>'  
                  .&Apache::loncommon::end_data_table_header_row());  
  foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {  
     $r->print(&Apache::loncommon::start_data_table_row()  
                      .'<td>'.$file.'</td>');  
     my ($ext)=($file=~/\.(\w+)$/);  
     my $title=$hash{'title_'.$hash{  
  'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};  
     $r->print('<td>'.($title?$title:'&nbsp;').'</td>');  
     if (!$title) {  
  $title=$file;  
     } else {  
  $title=~s|/|_|g;  
     }      }
     $title=~s/\.(\w+)$//;      my $title=$origcrsdata{'description'};
       $title=~s/[\/\s]+/\_/gs;
     $title=&clean($title);      $title=&clean($title);
     $title.='.'.$ext;      $preamble .= '<div class="LC_left_float">'.
     $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"                           '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
                      .&Apache::loncommon::end_data_table_row());                           '<input type="text" size="50" name="authorfolder" value="'.
  }                           $title.'" />'.
  $r->print(&Apache::loncommon::end_data_table());                           '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
  &untiehash();              my %uploadedfiles;
  $r->print(      &tiehash();
   '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype Content").'" /></p></form>');      foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
           my ($ext)=($file=~/\.(\w+)$/);
   # FIXME Check supplemental here
           my $title=$hash{'title_'.$hash{
                   'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
           if (!$title) {
       $title=$file;
           } else {
       $title=~s|/|_|g;
           }
           $title=~s/\.(\w+)$//;
           $title=&clean($title);
           $title.='.'.$ext;
   #    $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
                   $uploadedfiles{$file} = $title;
       }
       &untiehash();
               $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
                                                                    undef,undef,$preamble,$home,\%uploadedfiles));
           }
     }      }
     $r->print(&endContentScreen());      $r->print(&endContentScreen());
 }  }
   
   sub recurse_html {
       my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
       return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
       my (%allfiles,%codebase);
       if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
           if (keys(%allfiles)) {
               foreach my $dependency (keys(%allfiles)) {
                   next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
                   my ($depurl,$relfile,$newcontainer);
                   if ($dependency =~ m{^/}) {
                       if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
                           $relfile = $1;
                           if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
                               $newcontainer = $1;
                               next if ($replacehash->{$newcontainer});
                           }
                           $depurl = $dependency;
                       } else {
                           next;
                       }
                   } else {
                       $relfile = $dependency;
                       $depurl = $currurlpath;
                       $depurl =~ s{[^/]+$}{};  
                       $depurl .= $dependency;
                       ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$}); 
                   }
                   next if ($relfile eq '');
                   my $newname = $replacehash->{$container};
                   $newname =~ s{[^/]+$}{};
                   $replacehash->{$newcontainer} = $newname.$relfile;
                   $deps->{$item}{$newcontainer} = 1;
                   my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});  
                   my $depfile = &Apache::lonnet::filelocation('',$depurl);
                   my $type = $mm->checktype_filename($depfile);
                   if ($type eq 'text/html') {
                       &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
                   }
               }
           }
       }
       return;
   }
   
 sub group_import {  sub group_import {
     my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;      my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
     my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,      my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
Line 410  END Line 718  END
     unless ($fatal) {      unless ($fatal) {
         if ($folder =~ /^supplemental/) {          if ($folder =~ /^supplemental/) {
             &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);              &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
               my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
                                               $folder.'.'.$container);
         }          }
     }      }
     return ($errtext,$fatal,$fixuperrors);      return ($errtext,$fatal,$fixuperrors);
Line 710  sub update_paste_buffer { Line 1020  sub update_paste_buffer {
              my $url = $env{'docs.markedcopy_url_'.$suffix};               my $url = $env{'docs.markedcopy_url_'.$suffix};
              if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&               if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
                  ($url ne '')) {                   ($url ne '')) {
                  $pasteurls{$cid.'_'.$url};                   $pasteurls{$cid.'_'.$url} = 1;
              }               }
         }          }
     }      }
Line 1107  sub do_paste_from_buffer { Line 1417  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,%marktomove,$save_err,$lockerrors,$allresult);
         %msgs);  
   
     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});
Line 1309  sub do_paste_from_buffer { Line 1618  sub do_paste_from_buffer {
                     if ($prefix eq 'smppg') {                      if ($prefix eq 'smppg') {
                         $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;                          $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
                     } elsif ($prefix eq 'bulletinboard') {                      } elsif ($prefix eq 'bulletinboard') {
                         $msg = &mt('Paste failed: An error occurred when copying the bulletin board.').' '.$errtext;                          $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
                     }                      }
                     $results{$suffix} = $result;                      $results{$suffix} = $result;
                     $msgerrs{$suffix} = $msg;                      $msgerrs{$suffix} = $msg;
Line 1559  sub get_newmap_url { Line 1868  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);
     my $url = $dbref->{'src'};      $url = $dbref->{'src'};
     if (ref($dbref) eq 'HASH') {      if (ref($dbref) eq 'HASH') {
         if ($url =~ m{/(smppg|bulletinboard)$}) {          if ($url =~ m{/(smppg|bulletinboard)$}) {
             my $prefix = $1;              my $prefix = $1;
Line 1584  sub dbcopy { Line 1893  sub dbcopy {
                     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);
                     } else {                      } else {
                         $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a bulletin board [_1].',$url);                          $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
                     }                      }
                     if ($error) {                      if ($error) {
                         $errtext .= '<br />'.$error;                          $errtext .= '<br />'.$error;
Line 1620  sub dbcopy { Line 1929  sub dbcopy {
                     }                      }
                 }                  }
                 if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {                  if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
                     $lockerrorsref->{$prefix} =                       $lockerrorsref->{$prefix} =
                         '<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 ($prefix eq 'smppg') {                      if ($prefix eq 'smppg') {
                         $lockerrorsref->{$prefix} .=                           $lockerrorsref->{$prefix} .=
                             &mt('This will prevent creation of additional simple pages in this course.');                              ' '.&mt('This will prevent creation of additional simple pages in this course.');
                     } else {                      } else {
                         $lockerrorsref->{$prefix} .= &mt('This will prevent creation of additional bulletin boards in this course.');                          $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
                     }                      }
                     $lockerrorsref->{$prefix} .= &mt('Please contact the domain coordinator for your LON-CAPA domain.').'</div>';                      $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                                                        '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
                                                    '</div>';
                 }                  }
             }              }
         } elsif ($url =~ m{/syllabus$}) {          } elsif ($url =~ m{/syllabus$}) {
Line 3290  $form_common."\n". Line 3601  $form_common."\n".
                     push(@{$filtersref->{'randomorder'}},$orderidx);                      push(@{$filtersref->{'randomorder'}},$orderidx);
                 }                  }
             }              }
             my $formname = 'edit_rorder_'.$orderidx;              $formname = 'edit_rorder_'.$orderidx;
     $rand_order_text =       $rand_order_text = 
 '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".  '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
 $form_param."\n".  $form_param."\n".
Line 3493  sub new_timebased_suffix { Line 3804  sub new_timebased_suffix {
         } elsif ($type eq 'smppg') {          } elsif ($type eq 'smppg') {
             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');              $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
         } else {          } else {
             $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new bulletin board.');              $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
         }          }
         if ($error) {          if ($error) {
             $errtext .= '<br />'.$error;              $errtext .= '<br />'.$error;
Line 3512  sub new_timebased_suffix { Line 3823  sub new_timebased_suffix {
                 &mt('This will prevent creation of additional simple pages in this course.');                  &mt('This will prevent creation of additional simple pages in this course.');
         } else {          } else {
             $locknotfreed .=              $locknotfreed .=
                 &mt('This will prevent creation of additional bulletin boards in this course.');                  &mt('This will prevent creation of additional discussion boards in this course.');
         }          }
         unless ($type eq 'paste') {          unless ($type eq 'paste') {
             $locknotfreed .=              $locknotfreed .=
                 ' '.&mt('Please contact the domain coordinator for your LON-CAPA domain.');                  ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
                           '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
         }          }
         $locknotfreed .= '</div>';          $locknotfreed .= '</div>';
     }      }
Line 4155  sub handler { Line 4467  sub handler {
       &init_breadcrumbs('versions','Check/Set Resource Versions');        &init_breadcrumbs('versions','Check/Set Resource Versions');
       &checkversions($r);        &checkversions($r);
   } elsif ($allowed && $env{'form.dumpcourse'}) {    } elsif ($allowed && $env{'form.dumpcourse'}) {
       &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Content to Authoring Space');        &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
       &dumpcourse($r);        &dumpcourse($r);
   } elsif ($allowed && $env{'form.exportcourse'}) {    } elsif ($allowed && $env{'form.exportcourse'}) {
       &init_breadcrumbs('exportcourse','IMS Export');        &init_breadcrumbs('exportcourse','IMS Export');
Line 4181  sub handler { Line 4493  sub handler {
 # supplementalflag=0: show standard documents  # supplementalflag=0: show standard documents
 # toolsflag=1: show utilities  # toolsflag=1: show utilities
   
     $env{'form.folderpath'} = &unescape($env{'form.folderpath'});      my $unesc_folderpath = &unescape($env{'form.folderpath'});
     my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);      my $supplementalflag=($unesc_folderpath=~/^supplemental/);
     if (($env{'form.folderpath'}=~/^default/) || ($env{'form.folderpath'} eq "")) {      if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
        $supplementalflag=0;         $supplementalflag=0;
     }      }
     if ($env{'form.forcesupplement'}) { $supplementalflag=1; }      if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
Line 4993  my %suporderhash = ( Line 5305  my %suporderhash = (
                    foreach my $server (keys(%servers)) {                     foreach my $server (keys(%servers)) {
                        next if (grep(/^\Q$server\E$/,@ids));                         next if (grep(/^\Q$server\E$/,@ids));
                        my $hashid=$coursenum.':'.$coursedom;                         my $hashid=$coursenum.':'.$coursedom;
                        &Apache::lonnet::remote_devalidate_cache($server,'suppcount',$hashid);                         my $cachekey = &escape('suppcount').':'.&escape($hashid);
                          &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
                    }                     }
                    &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);                     &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
                    undef($suppchanges);                     undef($suppchanges);
Line 5145  sub remove_archive { Line 5458  sub remove_archive {
     } else {      } else {
         my $currcmd = $env{'form.cmd'};          my $currcmd = $env{'form.cmd'};
         my $position = $env{'form.position'};          my $position = $env{'form.position'};
         if ($position > 0) {           if ($position > 0) {
             $env{'form.cmd'} = 'del_'.$position;              $env{'form.cmd'} = 'remove_'.$position;
             my ($title,$url,@rrest) =               my ($title,$url,@rrest) = 
                 split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);                  split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
             if (&handle_edit_cmd($docuname,$docudom)) {              if (&handle_edit_cmd($docuname,$docudom)) {
Line 5181  sub generate_admin_menu { Line 5494  sub generate_admin_menu {
     my ($crstype) = @_;      my ($crstype) = @_;
     my $lc_crstype = lc($crstype);      my $lc_crstype = lc($crstype);
     my ($home,$other,%outhash)=&authorhosts();      my ($home,$other,%outhash)=&authorhosts();
     my %lt=&Apache::lonlocal::texthash (      my %lt= ( # do not translate here
                                          'vc'   => 'Verify Content',                                           'vc'   => 'Verify Content',
                                          'cv'   => 'Check/Set Resource Versions',                                           'cv'   => 'Check/Set Resource Versions',
                                          'ls'   => 'List Resource Identifiers',                                           'ls'   => 'List Resource Identifiers',
                                          'imse' => 'Export contents to IMS Archive',                                           'imse' => 'Export contents to IMS Archive',
                                          'dcd'  => "Dump $crstype Content to Authoring Space",                                           'dcd'  => "Copy $crstype Content to Authoring Space",
                                        );              );
     my ($candump,$dumpurl);      my ($candump,$dumpurl);
     if ($home + $other > 0) {      if ($home + $other > 0) {
         $candump = 'F';          $candump = 'F';
Line 6292  ENDINJECT Line 6605  ENDINJECT
 sub dump_switchserver_js {  sub dump_switchserver_js {
     my @hosts = @_;      my @hosts = @_;
     my %lt = &Apache::lonlocal::texthash(      my %lt = &Apache::lonlocal::texthash(
         dump => 'Dumping to Authoring Space requires switching server.',          dump => 'Copying Content to Authoring Space requires switching server.',
         swit => 'Switch server?',          swit => 'Switch server?',
         duco => 'Dump content to Authoring Space',          duco => 'Copying Content to Authoring Space',
         yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',          yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
         chos => 'Choose server',          chos => 'Choose server',
     );      );

Removed from v.1.558  
changed lines
  Added in v.1.568


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