Diff for /loncom/interface/loncommon.pm between versions 1.1066 and 1.1067

version 1.1066, 2012/04/06 01:23:11 version 1.1067, 2012/04/08 22:34:57
Line 9931  sub decompress_form { Line 9931  sub decompress_form {
     my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;      my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
     my %lt = &Apache::lonlocal::texthash (      my %lt = &Apache::lonlocal::texthash (
         this => 'This file is an archive file.',          this => 'This file is an archive file.',
           camt => 'This file is a Camtasia archive file.',
         itsc => 'Its contents are as follows:',          itsc => 'Its contents are as follows:',
         youm => 'You may wish to extract its contents.',          youm => 'You may wish to extract its contents.',
         camt => 'Extraction of contents is recommended for Camtasia zip files.',  
         extr => 'Extract contents',          extr => 'Extract contents',
           auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
           proa => 'Process automatically?',
         yes  => 'Yes',          yes  => 'Yes',
         no   => 'No',          no   => 'No',
           fold => 'Title for folder containing movie',
           movi => 'Title for page containing embedded movie', 
     );      );
     my $output = '<p>'.$lt{'this'};  
     my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);      my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
     my (%toplevel,@paths);      my ($is_camtasia,$topdir,%toplevel,@paths);
     my $info = &list_archive_contents($fileloc,\@paths);      my $info = &list_archive_contents($fileloc,\@paths);
     if (@paths) {      if (@paths) {
         foreach my $path (@paths) {          foreach my $path (@paths) {
             $path =~ s{^/}{};              $path =~ s{^/}{};
               if ($path =~ m{^([^/]+)/$}) {
                   $topdir = $1;
               }
             if ($path =~ m{^([^/]+)/}) {              if ($path =~ m{^([^/]+)/}) {
                 $toplevel{$1} = $path;                  $toplevel{$1} = $path;
             } else {              } else {
Line 9952  sub decompress_form { Line 9958  sub decompress_form {
             }              }
         }          }
     }      }
     if ($info eq '') {      if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
         $output .= ' '.$lt{'youm'}.'</p>'."\n";          my @camtasia = ("$topdir/","$topdir/index.html",
                           "$topdir/media/",
                           "$topdir/media/$topdir.mp4",
                           "$topdir/media/FirstFrame.png",
                           "$topdir/media/player.swf",
                           "$topdir/media/swfobject.js",
                           "$topdir/media/expressInstall.swf");
           my @diffs = &compare_arrays(\@paths,\@camtasia);
           if (@diffs == 0) {
               $is_camtasia = 1;
           }
       }
       my $output;
       if ($is_camtasia) {
           $output = <<"ENDCAM";
   <script type="text/javascript" language="Javascript">
   // <![CDATA[
   
   function camtasiaToggle() {
       for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
           if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
               if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
   
                   document.getElementById('camtasia_titles').style.display='block';
               } else {
                   document.getElementById('camtasia_titles').style.display='none';
               }
           }
       }
       return;
   }
   
   // ]]>
   </script>
   <p>$lt{'camt'}</p>
   ENDCAM
     } else {      } else {
         $output .= ' '.$lt{'itsc'}.'</p>'."\n".          $output = '<p>'.$lt{'this'};
                    '<div><pre>'.$info.'</pre></div>';          if ($info eq '') {
               $output .= ' '.$lt{'youm'}.'</p>'."\n";
           } else {
               $output .= ' '.$lt{'itsc'}.'</p>'."\n".
                          '<div><pre>'.$info.'</pre></div>';
           }
     }      }
       $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
     my $duplicates;      my $duplicates;
     my $num = 0;      my $num = 0;
     if (ref($dirlist) eq 'ARRAY') {      if (ref($dirlist) eq 'ARRAY') {
Line 9993  sub decompress_form { Line 10040  sub decompress_form {
     } else {      } else {
         $itemcount = 1;          $itemcount = 1;
     }      }
       if ($is_camtasia) {
           $output .= $lt{'auto'}.'<br />'.
                      '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
                      '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
                      $lt{'yes'}.'</label>&nbsp;<label>'.
                      '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
                      $lt{'no'}.'</label></span><br />'.
                      '<div id="camtasia_titles" style="display:block">'.
                      &Apache::lonhtmlcommon::start_pick_box().
                      &Apache::lonhtmlcommon::row_title($lt{'fold'}).
                      '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
                      &Apache::lonhtmlcommon::row_closure().
                      &Apache::lonhtmlcommon::row_title($lt{'movi'}).
                      '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
                      &Apache::lonhtmlcommon::row_closure(1).
                      &Apache::lonhtmlcommon::end_pick_box().
                      '</div>';
       }
     $output .=       $output .= 
         '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.          '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
         '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'."\n";          '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
           "\n";
     if ($duplicates ne '') {      if ($duplicates ne '') {
         $output .= '<p><span class="LC_warning">'.          $output .= '<p><span class="LC_warning">'.
                    &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.                       &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.  
Line 10011  sub decompress_form { Line 10077  sub decompress_form {
                    &end_data_table().                     &end_data_table().
                    '</p>';                     '</p>';
     }      }
     if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {      $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
         $output .= '<p>'.$lt{'camt'}.'</p>';  
     }  
     $output .= <<"START";  
 <div id="uploadfileresult">  
   <form name="uploaded_decompress" action="$action" method="post">  
   <input type="hidden" name="archiveurl" value="$archiveurl" />  
 START  
     if (ref($hiddenelements) eq 'HASH') {      if (ref($hiddenelements) eq 'HASH') {
         foreach my $hidden (sort(keys(%{$hiddenelements}))) {          foreach my $hidden (sort(keys(%{$hiddenelements}))) {
             $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";              $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
         }          }
     }      }
     $output .= <<"END";      $output .= <<"END";
   <br />
 <input type="submit" name="decompress" value="$lt{'extr'}" />  <input type="submit" name="decompress" value="$lt{'extr'}" />
 </form>  </form>
 $noextract  $noextract
 </div>  
 END  END
     return $output;      return $output;
 }  }
Line 10199  sub process_decompression { Line 10258  sub process_decompression {
                         }                          }
                     }                      }
                     if (@contents > 0) {                      if (@contents > 0) {
                           my $wantform;
                           unless ($env{'form.autoextract_camtasia'}) {
                               $wantform = 1;
                           }
                         my (%children,%parent,%dirorder,%titles);                          my (%children,%parent,%dirorder,%titles);
                         my $wantform = 1;  
                         my ($count,$datatable) = &get_extracted($docudom,$docuname,                          my ($count,$datatable) = &get_extracted($docudom,$docuname,
                                                                 $currdir,\%is_dir,                                                                  $currdir,\%is_dir,
                                                                 \%children,\%parent,                                                                  \%children,\%parent,
Line 10213  sub process_decompression { Line 10275  sub process_decompression {
                             $output .= &archive_javascript($startcount,$count,                              $output .= &archive_javascript($startcount,$count,
                                                            \%titles,\%children);                                                             \%titles,\%children);
                         }                          }
                           if ($env{'form.autoextract_camtasia'}) {
                               my %displayed;
                               my $total = 1;
                               $env{'form.archive_directory'} = [];
                               foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
                                   my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
                                   $path =~ s{/$}{};
                                   my $item;
                                   if ($path ne '') {
                                       $item = "$path/$titles{$i}";
                                   } else {
                                       $item = $titles{$i};
                                   }
                                   $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
                                   if ($item eq $contents[0]) {
                                       push(@{$env{'form.archive_directory'}},$i);
                                       $env{'form.archive_'.$i} = 'display';
                                       $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
                                       $displayed{'folder'} = $i;
                                   } elsif ($item eq "$contents[0]/index.html") {
                                       $env{'form.archive_'.$i} = 'display';
                                       $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
                                       $displayed{'web'} = $i;
                                   } else {
                                       if ($item eq "$contents[0]/media") {
                                           push(@{$env{'form.archive_directory'}},$i);
                                       }
                                       $env{'form.archive_'.$i} = 'dependency';
                                   }
                                   $total ++;
                               }
                               for (my $i=1; $i<$total; $i++) {
                                   next if ($i == $displayed{'web'});
                                   next if ($i == $displayed{'folder'});
                                   $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
                               }
                               $env{'form.phase'} = 'decompress_cleanup';
                               $env{'form.archivedelete'} = 1;
                               $env{'form.archive_count'} = $total-1;
                               $output .=
                                   &process_extracted_files('coursedocs',$docudom,
                                                            $docuname,$destination,
                                                            $dir_root,$hiddenelem);
                           }
                     } else {                      } else {
                         $warning = &mt('No new items extracted from archive file.');                          $warning = &mt('No new items extracted from archive file.');
                     }                      }
Line 10611  END Line 10717  END
 }  }
   
 sub process_extracted_files {  sub process_extracted_files {
     my ($context,$docudom,$docuname,$url,$destination,$dir_root,$hiddenelem) = @_;      my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
     my $numitems = $env{'form.archive_count'};      my $numitems = $env{'form.archive_count'};
     return unless ($numitems);      return unless ($numitems);
     my @ids=&Apache::lonnet::current_machine_ids();      my @ids=&Apache::lonnet::current_machine_ids();
     my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,      my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
         %folders,%containers,%mapinner);          %folders,%containers,%mapinner,%prompttofetch);
     my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);      my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
     if (grep(/^\Q$docuhome\E$/,@ids)) {      if (grep(/^\Q$docuhome\E$/,@ids)) {
         $prefix = &LONCAPA::propath($docudom,$docuname);          $prefix = &LONCAPA::propath($docudom,$docuname);
Line 10652  sub process_extracted_files { Line 10758  sub process_extracted_files {
             }              }
         }          }
     }      }
     my ($output,%children,%parent,%titles,%dirorder);      my ($output,%children,%parent,%titles,%dirorder,$result);
     if (keys(%toplevelitems) > 0) {      if (keys(%toplevelitems) > 0) {
         my @contents = sort(keys(%toplevelitems));          my @contents = sort(keys(%toplevelitems));
         (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,          (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
Line 10713  sub process_extracted_files { Line 10819  sub process_extracted_files {
                                                         $docuname.'/'.$folders{$outer}.                                                          $docuname.'/'.$folders{$outer}.
                                                         '.'.$containers{$outer},1);                                                          '.'.$containers{$outer},1);
                             $newseqid{$i} = $newidx;                              $newseqid{$i} = $newidx;
                               unless ($errtext) {
                                   $result .=  '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
                               }
                         }                          }
                     } else {                      } else {
                         if ($context eq 'coursedocs') {                          if ($context eq 'coursedocs') {
Line 10729  sub process_extracted_files { Line 10838  sub process_extracted_files {
                             if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {                              if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
                                 system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");                                  system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
                                 $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";                                  $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
                                   unless ($ishome) {
                                       my $fetch = "$newdest{$i}/$title";
                                       $fetch =~ s/^\Q$prefix$dir\E//;
                                       $prompttofetch{$fetch} = 1;
                                   }
                             }                              }
                             $LONCAPA::map::resources[$newidx]=                              $LONCAPA::map::resources[$newidx]=
                                 $docstitle.':'.$url.':false:normal:res';                                  $docstitle.':'.$url.':false:normal:res';
Line 10737  sub process_extracted_files { Line 10851  sub process_extracted_files {
                                 &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.                                  &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
                                                         $docuname.'/'.$folders{$outer}.                                                          $docuname.'/'.$folders{$outer}.
                                                         '.'.$containers{$outer},1);                                                          '.'.$containers{$outer},1);
                               unless ($errtext) {
                                   if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
                                       $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
                                   }
                               }
                         }                          }
                     }                      }
                 } elsif ($env{'form.archive_'.$i} eq 'dependency') {                  } elsif ($env{'form.archive_'.$i} eq 'dependency') {
Line 10744  sub process_extracted_files { Line 10863  sub process_extracted_files {
                     $referrer{$i} = $env{'form.archive_dependent_on_'.$i};                      $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
                     if ($env{'form.archive_'.$referrer{$i}} eq 'display') {                      if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
                         if (ref($dirorder{$i}) eq 'ARRAY') {                          if (ref($dirorder{$i}) eq 'ARRAY') {
                             my ($itemidx,$fullpath);                              my ($itemidx,$fullpath,$relpath);
                             for (my $j=0; $j<@{$dirorder{$i}}; $j++) {                              for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
                                 if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {                                  if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
                                     my $container = $dirorder{$referrer{$i}}->[-1];                                      my $container = $dirorder{$referrer{$i}}->[-1];
Line 10763  sub process_extracted_files { Line 10882  sub process_extracted_files {
                                             if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {                                              if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
                                                 unless (defined($newseqid{$dirorder{$i}->[$j]})) {                                                  unless (defined($newseqid{$dirorder{$i}->[$j]})) {
                                                     $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};                                                      $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
                                                       $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
                                                     if (!-e $fullpath) {                                                      if (!-e $fullpath) {
                                                         mkdir($fullpath,0755);                                                          mkdir($fullpath,0755);
                                                     }                                                      }
Line 10781  sub process_extracted_files { Line 10901  sub process_extracted_files {
                                         } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {                                          } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
                                             unless (defined($newseqid{$dirorder{$i}->[$j]})) {                                              unless (defined($newseqid{$dirorder{$i}->[$j]})) {
                                                 $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};                                                  $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
                                                   $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
                                                 if (!-e $fullpath) {                                                  if (!-e $fullpath) {
                                                     mkdir($fullpath,0755);                                                      mkdir($fullpath,0755);
                                                 }                                                  }
Line 10791  sub process_extracted_files { Line 10912  sub process_extracted_files {
                                     }                                      }
                                 }                                  }
                                 if ($fullpath ne '') {                                  if ($fullpath ne '') {
                                     system("mv $prefix$path $fullpath/$title");                                      if (-e "$prefix$path") {
                                           system("mv $prefix$path $fullpath/$title");
                                       }
                                       if (-e "$fullpath/$title") {
                                           my $showpath;
                                           if ($relpath ne '') {
                                               $showpath = "$relpath/$title";
                                           } else {
                                               $showpath = "/$title";
                                           } 
                                           $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
                                       } 
                                       unless ($ishome) {
                                           my $fetch = "$fullpath/$title";
                                           $fetch =~ s/^\Q$prefix$dir\E//; 
                                           $prompttofetch{$fetch} = 1;
                                       }
                                 }                                  }
                             }                              }
                         }                          }
Line 10819  sub process_extracted_files { Line 10956  sub process_extracted_files {
                 &cleanup_empty_dirs($prefix."$pathtocheck/$dir");                  &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
             }              }
         }          }
           if ($result ne '') {
               $output .= '<ul>'."\n".
                          $result."\n".
                          '</ul>';
           }
           unless ($ishome) {
               my $replicationfail;
               foreach my $item (keys(%prompttofetch)) {
                   my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
                   unless ($fetchresult eq 'ok') {
                       $replicationfail .= '<li>'.$item.'</li>'."\n";
                   }
               }
               if ($replicationfail) {
                   $output .= '<p class="LC_error">'.
                              &mt('Course home server failed to retrieve:').'<ul>'.
                              $replicationfail.
                              '</ul></p>';
               }
           }
     } else {      } else {
         $warning = &mt('No items found in archive.');          $warning = &mt('No items found in archive.');
     }      }

Removed from v.1.1066  
changed lines
  Added in v.1.1067


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