[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm

raeburn raeburn at source.lon-capa.org
Mon Apr 16 15:30:56 EDT 2012


raeburn		Mon Apr 16 19:30:56 2012 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  Bug 6448 - Manage dependencies for HTML files uploaded to course.
  - New routines: &get_dependency_details() and & ask_embedded_js()
    to provide information about previously uploaded dependencies
    and javascript to toggle div used to upload replacement.
  - In case where references within parent web page need to be modified
    &modify_html_refs() will now return either an array if requested:
    $output,$count,$codebasecount  or in scalar context just $output. 
  
  
-------------- next part --------------
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1070 loncom/interface/loncommon.pm:1.1071
--- loncom/interface/loncommon.pm:1.1070	Wed Apr 11 15:53:22 2012
+++ loncom/interface/loncommon.pm	Mon Apr 16 19:30:56 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1070 2012/04/11 15:53:22 raeburn Exp $
+# $Id: loncommon.pm,v 1.1071 2012/04/16 19:30:56 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -9165,13 +9165,20 @@
 
 sub ask_for_embedded_content {
     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
-    my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges);
-    my $num = 0;
+    my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
+        %currsubfile,%unused);
+    my $counter = 0;
+    my $numnew = 0;
     my $numremref = 0;
     my $numinvalid = 0;
     my $numpathchg = 0;
     my $numexisting = 0;
-    my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath);
+    my $numunused = 0;
+    my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
+        $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
+    my $heading = &mt('Upload embedded files');
+    my $buttontext = &mt('Upload');
+
     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
         my $current_path='/';
         if ($env{'form.currentpath'}) {
@@ -9199,8 +9206,24 @@
         }
     } elsif ($actionurl eq '/adm/coursedocs') {
         if (ref($args) eq 'HASH') {
-           $url = $args->{'docs_url'};
-           $toplevel = $url;
+            $url = $args->{'docs_url'};
+            $toplevel = $url;
+        }
+    } elsif ($actionurl eq '/adm/dependencies') {
+        if ($env{'request.course.id'} ne '') {
+            $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+            $cnum =  $env{'course.'.$env{'request.course.id'}.'.num'};
+            if (ref($args) eq 'HASH') {
+                $url = $args->{'docs_url'};
+                $title = $args->{'docs_title'};
+                $toplevel = "/$url";
+                ($path) =  
+                    ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
+                $fileloc = &Apache::lonnet::filelocation('',$toplevel);
+                $fileloc =~ s{^/}{};
+                ($filename) = ($fileloc =~ m{.+/([^/]+)$});
+                $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
+            }
         }
     }
     my $now = time();
@@ -9239,25 +9262,44 @@
             }
         }
     }
+    my $dirptr = 16384;
     foreach my $path (keys(%subdependencies)) {
-        my %currsubfile;
+        $currsubfile{$path} = {};
         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { 
             my ($sublistref,$listerror) =
                 &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
             if (ref($sublistref) eq 'ARRAY') {
                 foreach my $line (@{$sublistref}) {
                     my ($file_name,$rest) = split(/\&/,$line,2);
-                    $currsubfile{$file_name} = 1;
+                    $currsubfile{$path}{$file_name} = 1;
                 }
             }
         } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
             if (opendir(my $dir,$url.'/'.$path)) {
                 my @subdir_list = grep(!/^\./,readdir($dir));
-                map {$currsubfile{$_} = 1;} @subdir_list;
+                map {$currsubfile{$path}{$_} = 1;} @subdir_list;
+            }
+        } elsif ($actionurl eq '/adm/dependencies') {
+            if ($env{'request.course.id'} ne '') {
+                my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
+                if ($dir ne '') {
+                    my ($sublistref,$listerror) =
+                        &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
+                    if (ref($sublistref) eq 'ARRAY') {
+                        foreach my $line (@{$sublistref}) {
+                            my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
+                                undef,$mtime)=split(/\&/,$line,12);
+                            unless (($testdir&$dirptr) ||
+                                    ($file_name =~ /^\.\.?$/)) {
+                                $currsubfile{$path}{$file_name} = [$size,$mtime];
+                            }
+                        }
+                    }
+                }
             }
         }
         foreach my $file (keys(%{$subdependencies{$path}})) {
-            if ($currsubfile{$file}) {
+            if (exists($currsubfile{$path}{$file})) {
                 my $item = $path.'/'.$file;
                 unless ($mapping{$item} eq $item) {
                     $pathchanges{$item} = 1;
@@ -9268,6 +9310,17 @@
                 $newfiles{$path.'/'.$file} = 1;
             }
         }
+        if ($actionurl eq '/adm/dependencies') {
+            foreach my $path (keys(%currsubfile)) {
+                if (ref($currsubfile{$path}) eq 'HASH') {
+                    foreach my $file (keys(%{$currsubfile{$path}})) {
+                         unless ($subdependencies{$path}{$file}) {
+                             $unused{$path.'/'.$file} = 1; 
+                         }
+                    }
+                }
+            }
+        }
     }
     my %currfile;
     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
@@ -9284,9 +9337,27 @@
             my @dir_list = grep(!/^\./,readdir($dir));
             map {$currfile{$_} = 1;} @dir_list;
         }
+    } elsif ($actionurl eq '/adm/dependencies') {
+        if ($env{'request.course.id'} ne '') {
+            my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
+            if ($dir ne '') {
+                my ($dirlistref,$listerror) =
+                    &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
+                if (ref($dirlistref) eq 'ARRAY') {
+                    foreach my $line (@{$dirlistref}) {
+                        my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
+                            $size,undef,$mtime)=split(/\&/,$line,12);
+                        unless (($testdir&$dirptr) ||
+                                ($file_name =~ /^\.\.?$/)) {
+                            $currfile{$file_name} = [$size,$mtime];
+                        }
+                    }
+                }
+            }
+        }
     }
     foreach my $file (keys(%dependencies)) {
-        if ($currfile{$file}) {
+        if (exists($currfile{$file})) {
             unless ($mapping{$file} eq $file) {
                 $pathchanges{$file} = 1;
             }
@@ -9296,15 +9367,25 @@
             $newfiles{$file} = 1;
         }
     }
+    foreach my $file (keys(%currfile)) {
+        unless (($file eq $filename) ||
+                ($file eq $filename.'.bak') ||
+                ($dependencies{$file})) {
+            $unused{$file} = 1;
+        }
+    }
     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
+        if ($actionurl eq '/adm/dependencies') {
+            next if ($embed_file =~ m{^\w+://});
+        }
         $upload_output .= &start_data_table_row().
-                          '<td><span class="LC_filename">'.$embed_file.'</span>';
+                          '<td><img src="'.&icon($embed_file).'" /> '.
+                          '<span class="LC_filename">'.$embed_file.'</span>';
         unless ($mapping{$embed_file} eq $embed_file) {
             $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
         }
         $upload_output .= '</td><td>';
-        if ($args->{'ignore_remote_references'}
-            && $embed_file =~ m{^\w+://}) {
+        if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) { 
             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
             $numremref++;
         } elsif ($args->{'error_on_invalid_names'}
@@ -9313,24 +9394,84 @@
             $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
             $numinvalid++;
         } else {
-            $upload_output .= &embedded_file_element('upload_embedded',$num,
+            $upload_output .= &embedded_file_element('upload_embedded',$counter,
                                                      $embed_file,\%mapping,
-                                                     $allfiles,$codebase);
-            $num++;
+                                                     $allfiles,$codebase,'upload');
+            $counter ++;
+            $numnew ++;
         }
         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
     }
     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
-        $upload_output .= &start_data_table_row().
-                          '<td><span class="LC_filename">'.$embed_file.'</span></td>'.
-                          '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
-                          &Apache::loncommon::end_data_table_row()."\n";
+        if ($actionurl eq '/adm/dependencies') {
+            my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
+            $modify_output .= &start_data_table_row().
+                              '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
+                              '<img src="'.&icon($embed_file).'" border="0" />'.
+                              ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
+                              '<td>'.$size.'</td>'.
+                              '<td>'.$mtime.'</td>'.
+                              '<td><label><input type="checkbox" name="mod_upload_dep" '.
+                              'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
+                              $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
+                              '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
+                              &embedded_file_element('upload_embedded',$counter,
+                                                     $embed_file,\%mapping,
+                                                     $allfiles,$codebase,'modify').
+                              '</div></td>'.
+                              &end_data_table_row()."\n";
+            $counter ++;
+        } else {
+            $upload_output .= &start_data_table_row().
+                              '<td><span class="LC_filename">'.$embed_file.'</span></td>';
+                              '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
+                              &Apache::loncommon::end_data_table_row()."\n";
+        }
+    }
+    my $delidx = $counter;
+    foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
+        my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
+        $delete_output .= &start_data_table_row().
+                          '<td><img src="'.&icon($oldfile).'" />'.
+                          ' <span class="LC_filename">'.$oldfile.'</span></td>'.
+                          '<td>'.$size.'</td>'.
+                          '<td>'.$mtime.'</td>'.
+                          '<td><label><input type="checkbox" name="del_upload_dep" '.
+                          ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
+                          &embedded_file_element('upload_embedded',$delidx,
+                                                 $oldfile,\%mapping,$allfiles,
+                                                 $codebase,'delete').'</td>'.
+                          &end_data_table_row()."\n"; 
+        $numunused ++;
+        $delidx ++;
     }
     if ($upload_output) {
         $upload_output = &start_data_table().
                          $upload_output.
                          &end_data_table()."\n";
     }
+    if ($modify_output) {
+        $modify_output = &start_data_table().
+                         &start_data_table_header_row().
+                         '<th>'.&mt('File').'</th>'.
+                         '<th>'.&mt('Size (KB)').'</th>'.
+                         '<th>'.&mt('Modified').'</th>'.
+                         '<th>'.&mt('Upload replacement?').'</th>'.
+                         &end_data_table_header_row().
+                         $modify_output.
+                         &end_data_table()."\n";
+    }
+    if ($delete_output) {
+        $delete_output = &start_data_table().
+                         &start_data_table_header_row().
+                         '<th>'.&mt('File').'</th>'.
+                         '<th>'.&mt('Size (KB)').'</th>'.
+                         '<th>'.&mt('Modified').'</th>'.
+                         '<th>'.&mt('Delete?').'</th>'.
+                         &end_data_table_header_row().
+                         $delete_output.
+                         &end_data_table()."\n";
+    }
     my $applies = 0;
     if ($numremref) {
         $applies ++;
@@ -9341,15 +9482,37 @@
     if ($numexisting) {
         $applies ++;
     }
-    if ($num) {
+    if ($counter || $numunused) {
         $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
                   ' method="post" enctype="multipart/form-data">'."\n".
-                  $state.
-                  '<h3>'.&mt('Upload embedded files').
-                  ':</h3>'.$upload_output.'<br />'."\n".
-                  '<input type ="hidden" name="number_embedded_items" value="'.
-                  $num.'" />'."\n";
-        if ($actionurl eq '') {
+                  $state.'<h3>'.$heading.'</h3>'; 
+        if ($actionurl eq '/adm/dependencies') {
+            if ($numnew) {
+                $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
+                           '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
+                           $upload_output.'<br />'."\n";
+            }
+            if ($numexisting) {
+                $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
+                           '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
+                           $modify_output.'<br />'."\n";
+                           $buttontext = &mt('Save changes');
+            }
+            if ($numunused) {
+                $output .= '<h4>'.&mt('Unused files').'</h4>'.
+                           '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
+                           $delete_output.'<br />'."\n";
+                           $buttontext = &mt('Save changes');
+            }
+        } else {
+            $output .= $upload_output.'<br />'."\n";
+        }
+        $output .= '<input type ="hidden" name="number_embedded_items" value="'.
+                   $counter.'" />'."\n";
+        if ($actionurl eq '/adm/dependencies') { 
+            $output .= '<input type ="hidden" name="number_newemb_items" value="'.
+                       $numnew.'" />'."\n";
+        } elsif ($actionurl eq '') {
             $output .=  '<input type="hidden" name="phase" value="three" />';
         }
     } elsif ($applies) {
@@ -9377,13 +9540,13 @@
         $output .= $upload_output.'<br />';
     }
     my ($pathchange_output,$chgcount);
-    $chgcount = $num;
+    $chgcount = $counter;
     if (keys(%pathchanges) > 0) {
         foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
-            if ($num) {
+            if ($counter) {
                 $output .= &embedded_file_element('pathchange',$chgcount,
                                                   $embed_file,\%mapping,
-                                                  $allfiles,$codebase);
+                                                  $allfiles,$codebase,'change');
             } else {
                 $pathchange_output .= 
                     &start_data_table_row().
@@ -9392,14 +9555,14 @@
                     '<td>'.$mapping{$embed_file}.'</td>'.
                     '<td>'.$embed_file.
                     &embedded_file_element('pathchange',$numpathchg,$embed_file,
-                                           \%mapping,$allfiles,$codebase).
+                                           \%mapping,$allfiles,$codebase,'change').
                     '</td>'.&end_data_table_row();
             }
             $numpathchg ++;
             $chgcount ++;
         }
     }
-    if ($num) {
+    if ($counter) {
         if ($numpathchg) {
             $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
                        $numpathchg.'" />'."\n";
@@ -9409,9 +9572,10 @@
             $output .= '<input type="hidden" name="phase" value="three" />'."\n";
         } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
             $output .= '<input type="hidden" name="action" value="upload_embedded" />';
+        } elsif ($actionurl eq '/adm/dependencies') {
+            $output .= '<input type="hidden" name="action" value="process_changes" />';
         }
-        $output .=  '<input type ="submit" value="'.&mt('Upload Listed Files').'" />'."\n".
-                    &mt('(only files for which a location has been provided will be uploaded)').'</form>'."\n";
+        $output .=  '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
     } elsif ($numpathchg) {
         my %pathchange = ();
         $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
@@ -9419,15 +9583,15 @@
             $output .= '<p>'.&mt('or').'</p>'; 
         } 
     }
-    return ($output,$num,$numpathchg);
+    return ($output,$counter,$numpathchg);
 }
 
 sub embedded_file_element {
-    my ($context,$num,$embed_file,$mapping,$allfiles,$codebase) = @_;
+    my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
     return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
                    (ref($codebase) eq 'HASH'));
     my $output;
-    if ($context eq 'upload_embedded') {
+    if (($context eq 'upload_embedded') && ($type ne 'delete')) {
        $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
     }
     $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
@@ -9454,6 +9618,50 @@
     return $output;
 }
 
+sub get_dependency_details {
+    my ($currfile,$currsubfile,$embed_file) = @_;
+    my ($size,$mtime,$showsize,$showmtime);
+    if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
+        if ($embed_file =~ m{/}) {
+            my ($path,$fname) = split(/\//,$embed_file);
+            if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
+                ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
+            }
+        } else {
+            if (ref($currfile->{$embed_file}) eq 'ARRAY') {
+                ($size,$mtime) = @{$currfile->{$embed_file}};
+            }
+        }
+        $showsize = $size/1024.0;
+        $showsize = sprintf("%.1f",$showsize);
+        if ($mtime > 0) {
+            $showmtime = &Apache::lonlocal::locallocaltime($mtime);
+        }
+    }
+    return ($showsize,$showmtime);
+}
+
+sub ask_embedded_js {
+    return <<"END";
+<script type="text/javascript"">
+// <![CDATA[
+function toggleBrowse(counter) {
+    var chkboxid = document.getElementById('mod_upload_dep_'+counter);
+    var fileid = document.getElementById('embedded_item_'+counter);
+    var uploaddivid = document.getElementById('moduploaddep_'+counter);
+    if (chkboxid.checked == true) {
+        uploaddivid.style.display='block';
+    } else {
+        uploaddivid.style.display='none';
+        fileid.value = '';
+    }
+}
+// ]]>
+</script>
+
+END
+}
+
 sub upload_embedded {
     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
         $current_disk_usage,$hiddenstate,$actionurl) = @_;
@@ -9512,7 +9720,6 @@
             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
             next;
         }
-
         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
         if ($context eq 'portfolio') {
             my $result;
@@ -9569,13 +9776,15 @@
             if (!open($fh,'>'.$dest)) {
                 &Apache::lonnet::logthis('Failed to create '.$dest);
                 $output .= '<span class="LC_error">'.
-                           &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
+                           &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
+                               $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                            '</span><br />';
             } else {
                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                     $output .= '<span class="LC_error">'.
-                              &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
+                              &mt('An error occurred while writing the file [_1] for embedded element [_2].',
+                                  $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                               '</span><br />';
                 } else {
                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
@@ -9597,15 +9806,17 @@
     }
     $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
     $returnflag = 'ok';
-    if (keys(%pathchange) > 0) {
+    my $numpathchgs = scalar(keys(%pathchange));
+    if ($numpathchgs > 0) {
         if ($context eq 'portfolio') {
             $output .= '<p>'.&mt('or').'</p>';
         } elsif ($context eq 'testbank') {
-            $output .=  '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).','<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
+            $output .=  '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
+                                  '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
             $returnflag = 'modify_orightml';
         }
     }
-    return ($output.$footer,$returnflag);
+    return ($output.$footer,$returnflag,$numpathchgs);
 }
 
 sub modify_html_form {
@@ -9640,7 +9851,7 @@
                     '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
                     &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
                     &end_data_table_row();
-            } 
+            }
         }
     } else {
         $modifyform = $pathchgtable;
@@ -9651,6 +9862,9 @@
         }
     }
     if ($modifyform) {
+        if ($actionurl eq '/adm/dependencies') {
+            $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
+        }
         return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
                '<p>'.&mt('Changes need to be made to the reference(s) used for one or more of the dependencies, if your HTML file is to work correctly:').'<ol>'."\n".
                '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
@@ -9679,23 +9893,55 @@
         $container = $env{'form.container'};
     } elsif ($context eq 'coursedoc') {
         $container = $env{'form.primaryurl'};
+    } elsif ($context eq 'manage_dependencies') {
+        (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
+        $container = "/$container";
     } else {
         $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
     }
     my (%allfiles,%codebase,$output,$content);
     my @changes = &get_env_multiple('form.namechange');
-    return unless (@changes > 0);
-    if (($context eq 'portfolio') || ($context eq 'coursedoc')) {
-        return unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/});
+    unless (@changes > 0) {
+        if (wantarray) {
+            return ('',0,0); 
+        } else {
+            return;
+        }
+    }
+    if (($context eq 'portfolio') || ($context eq 'coursedoc') || 
+        ($context eq 'manage_dependencies')) {
+        unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
+            if (wantarray) {
+                return ('',0,0);
+            } else {
+                return;
+            }
+        } 
         $content = &Apache::lonnet::getfile($container);
-        return if ($content eq '-1');
+        if ($content eq '-1') {
+            if (wantarray) {
+                return ('',0,0);
+            } else {
+                return;
+            }
+        }
     } else {
-        return unless ($container =~ /^\Q$dir_root\E/); 
+        unless ($container =~ /^\Q$dir_root\E/) {
+            if (wantarray) {
+                return ('',0,0);
+            } else {
+                return;
+            }
+        } 
         if (open(my $fh,"<$container")) {
             $content = join('', <$fh>);
             close($fh);
         } else {
-            return;
+            if (wantarray) {
+                return ('',0,0);
+            } else {
+                return;
+            }
         }
     }
     my ($count,$codebasecount) = (0,0);
@@ -9729,13 +9975,14 @@
             }
             if ($count || $codebasecount) {
                 my $saveresult;
-                if ($context eq 'portfolio' || $context eq 'coursedoc') {
+                if (($context eq 'portfolio') || ($context eq 'coursedoc') || 
+                    ($context eq 'manage_dependencies')) {
                     my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
                     if ($url eq $container) {
                         my ($fname) = ($container =~ m{/([^/]+)$});
                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                                             $count,'<span class="LC_filename">'.
-                                            $fname.'</span>').'</p>'; 
+                                            $fname.'</span>').'</p>';
                     } else {
                          $output = '<p class="LC_error">'.
                                    &mt('Error: update failed for: [_1].',
@@ -9762,7 +10009,11 @@
                      ' to modify references: '.$parse_result);
         }
     }
-    return $output;
+    if (wantarray) {
+        return ($output,$count,$codebasecount);
+    } else {
+        return $output;
+    }
 }
 
 sub check_for_existing {
@@ -11058,15 +11309,15 @@
                     }
                 }
             }
-        }
-        if ($showitem) {
-            if ($mapres->{ID} eq '0.0') {
-                push(@pathitems,&mt('Main Course Documents'));
-            } else {
-                my $maptitle = $mapres->compTitle();
-                $maptitle =~ s/\W+/_/g;
-                if ($maptitle ne '') {
-                    push(@pathitems,$maptitle);
+            if ($showitem) {
+                if ($mapres->{ID} eq '0.0') {
+                    push(@pathitems,&mt('Main Course Documents'));
+                } else {
+                    my $maptitle = $mapres->compTitle();
+                    $maptitle =~ s/\W+/_/g;
+                    if ($maptitle ne '') {
+                        push(@pathitems,$maptitle);
+                    }
                 }
             }
         }
@@ -13380,7 +13631,9 @@
     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
     if ($symb eq '') {
         if (!$silent) {
-            $request->print("Unable to handle ambiguous references:$url:.");
+            if (ref($request)) { 
+                $request->print("Unable to handle ambiguous references:$url:.");
+            }
             return ();
         }
     }


More information about the LON-CAPA-cvs mailing list