[LON-CAPA-cvs] cvs: loncom /interface lonblockingmenu.pm loncourserespicker.pm londocs.pm

raeburn raeburn at source.lon-capa.org
Tue Nov 12 09:36:08 EST 2013


raeburn		Tue Nov 12 14:36:08 2013 EDT

  Modified files:              
    /loncom/interface	lonblockingmenu.pm loncourserespicker.pm 
                     	londocs.pm 
  Log:
  - Bug 4331 Dumping from Course to Authoring Space can include simple pages
    and simpleproblems.
    - &enumerate_course_contents() moved from lonblockingmenu.pm to 
      loncourserespicker.pm to facilitate reuse.
    - loncourserespicker::create_picker() modified to support choice of items
      to dump to Authoring Space.
    - POD updated.   
  
  
-------------- next part --------------
Index: loncom/interface/lonblockingmenu.pm
diff -u loncom/interface/lonblockingmenu.pm:1.9 loncom/interface/lonblockingmenu.pm:1.10
--- loncom/interface/lonblockingmenu.pm:1.9	Fri Jan  4 05:45:50 2013
+++ loncom/interface/lonblockingmenu.pm	Tue Nov 12 14:36:07 2013
@@ -2,7 +2,7 @@
 # Routines for configuring blocking of access to collaborative functions, 
 # and specific resources during an exam
 #
-# $Id: lonblockingmenu.pm,v 1.9 2013/01/04 05:45:50 raeburn Exp $
+# $Id: lonblockingmenu.pm,v 1.10 2013/11/12 14:36:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -135,27 +135,6 @@
       $output - Information about changes made.
 
 
-=item &enumerate_course_contents()
-
-Create hashes of maps (for folders/pages) and symbs (for resources) in
-a course, where keys are numbers (starting with 1) and values are
-map url, or symb, for an iteration through the course, as seen by
-a Course Coordinator. Used to generate numerical IDs to facilitate
-storage of lists of maps or resources to be blocked during an exam.   
-
-Inputs: 3
-      $navmap - navmaps object
-
-      $map_url - reference to hash to contain URLs of maps in course
-
-      $resource_symb - reference to hash to contain symbs for
-                       resources in course
-
-Outputs: None
-
-Side Effects: $map_url and $resource_symb hashrefs are populated.
-
-
 =item &get_dates_from_form()
 
 Extract start and end dates from web form input for blocks with
@@ -388,6 +367,7 @@
 use Apache::loncommon();
 use Apache::lonhtmlcommon();
 use Apache::lonparmset();
+use Apache::loncourserespicker();
 use HTML::Entities();
 use Apache::lonlocal;
 use lib '/home/httpd/lib/perl/';
@@ -664,7 +644,7 @@
     my $changestotal = 0;
     my $addtimer = 0;
     my %blocking = ();
-    my (%map_url,%resource_symb,$output);
+    my (%map_url,%resource_symb,%titles,$output);
     $output = '<h3>'.$lt{'head'}.'</h3>';
     if ($env{'form.blockaction'} eq 'modify') {
         foreach my $envkey (keys(%env)) {
@@ -690,7 +670,7 @@
         $output = $lt{'unna'}.' '.$lt{'ncwm'}.'</br>';
         return ($changestotal,$output);
     }
-    &enumerate_course_contents($navmap,\%map_url,\%resource_symb);
+    &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock');
     foreach my $key (keys(%removals)) {
         my $hashkey = $env{'form.key_'.$key};
         &Apache::lonnet::del('comm_block',["$hashkey"],
@@ -800,34 +780,6 @@
     return ($changestotal,$output);
 }
 
-sub enumerate_course_contents {
-    my ($navmap,$map_url,$resource_symb) = @_;
-    if ((ref($navmap)) && (ref($map_url) eq 'HASH') && 
-        (ref($resource_symb) eq 'HASH')) {
-        my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
-        my $count = 0;
-        while (my $curRes = $it->next()) {
-            if (ref($curRes)) {
-                $count ++;
-                my $symb = $curRes->symb();
-                my $ressymb = $symb;
-                if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
-                    unless ($ressymb =~ m|adm/wrapper/adm|) {
-                        $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.
-                                   '/bulletinboard';
-                    }
-                }
-                if (($curRes->is_sequence()) || ($curRes->is_page())) {
-                    $map_url->{$count} = (&Apache::lonnet::decode_symb($symb))[2];
-                } else {
-                    $resource_symb->{$count} = $ressymb;
-                }
-            }
-        }
-    }
-    return;
-}
-
 sub get_dates_from_form {
     my $item = shift;
     my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$item);
@@ -916,8 +868,8 @@
 sub display_blocker_status {
     my ($r,$records,$ltext,$intervals,$navmap,$errormsg,$blockcount) = @_;
     my $parmcount = 0;
-    my (%map_url,%resource_symb,%lookups);
-    &enumerate_course_contents($navmap,\%map_url,\%resource_symb);
+    my (%map_url,%resource_symb,%titles,%lookups);
+    &Apache::loncourserespicker::enumerate_course_contents($navmap,\%map_url,\%resource_symb,\%titles,'examblock');
     %{$lookups{'maps'}} = reverse(%map_url);
     %{$lookups{'resources'}} = reverse(%resource_symb);
     my %lt = &Apache::lonlocal::texthash(
Index: loncom/interface/loncourserespicker.pm
diff -u loncom/interface/loncourserespicker.pm:1.6 loncom/interface/loncourserespicker.pm:1.7
--- loncom/interface/loncourserespicker.pm:1.6	Tue May 21 18:54:15 2013
+++ loncom/interface/loncourserespicker.pm	Tue Nov 12 14:36:07 2013
@@ -1,6 +1,6 @@
 # The LearningOnline Network
 #
-# $Id: loncourserespicker.pm,v 1.6 2013/05/21 18:54:15 raeburn Exp $
+# $Id: loncourserespicker.pm,v 1.7 2013/11/12 14:36:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -37,7 +37,8 @@
 resources are to be either:
 
 (a) exported to an IMS Content Package
-(b) subject to access blocking for the duriation of an exam/quiz.  
+(b) subject to access blocking for the duriation of an exam/quiz.
+(c) dumped to an Authoring Space
 
 =head1 DESCRIPTION
 
@@ -59,11 +60,11 @@
 a higher level to become unchecked.
 
 There is a submit button, which will be named differently according to the 
-content in which resource/folder selection is being made.
+context in which resource/folder selection is being made.
 
-The two contexts currently supported are: IMS export and selection of
+The three contexts currently supported are: IMS export, selection of
 content to be subject to access restructions for the duration of an
-exam.  
+exam, and selection of items for dumping to an Authoring Space.
 
 =head1 INTERNAL SUBROUTINES
 
@@ -74,7 +75,7 @@
 within the folder. Unchecking a resource causing unchecking of folders
 containing the item back up to the top level.
 
-Inputs: 7.
+Inputs: 9.
    - $navmap  -- Reference to LON-CAPA navmap object 
                 (encapsulates information about resources in the course). 
 
@@ -95,6 +96,17 @@
    - $block  -- An internal ID (integer) used to track which exam
                 block currently being configured.
 
+   - $preamble -- HTML form elements used to select Authoring Space
+                  if more than one available, and also set name of 'Folder 
+                  in Authoring Space' where content will be dumped, when
+                  context is 'dumpdocs'.
+
+   - $numhome -- number of possible Authoring Spaces where content could
+                 be dumped when context is 'dumpdocs'.
+
+   - $uploadedfiles -- Reference to hash: keys are paths to files in
+                       /home/httpd/lonUsers/$cdom/$1/$2/$3/$cnum/userfiles.
+
 
 Output: $output is the HTML mark-up for display/selection of content
         items in the pop-up window.
@@ -111,7 +123,7 @@
    - $numcount -- Total numer of folders and resources in course.
 
    - $context -- Context in which resources are being displayed
-                 (imsexport or examblock). 
+                 (imsexport, examblock or dumpdocs). 
 
    - $formname --  Name of form.
 
@@ -121,7 +133,7 @@
 
    - $checked_maps -- Reference to array of folders currently checked.
 
-Output: 1. Javascript (witthin <script></script> tags.
+Output: 1. Javascript (within <script></script> tags.
 
 
 =item &get_navmap_object() 
@@ -132,7 +144,48 @@
 Inputs: 2.
    - $crstype -- Container type: Course or Community
 
-   - $context -- Context: imsexport or examblock
+   - $context -- Context: imsexport, examblock or dumpdocs
+
+
+=item &clean()
+ 
+Takes incoming title and replaces non-alphanumeric characters with underscore,
+so title can be used as suggested file name (with appended extension) for file
+copied from course to Authoring space.
+
+
+=item &enumerate_course_contents()
+
+Create hashes of maps (for folders/pages) and symbs (for resources) in
+a course, where keys are numbers (starting with 1) and values are
+map url, or symb, for an iteration through the course, as seen by
+a Course Coordinator. Used to generate numerical IDs to facilitate
+(a) storage of lists of maps or resources to be blocked during an exam,
+(b) processing selected form element during dumping of selected course
+    content to Authoring space.
+
+Inputs: 7 
+
+      $navmap - navmaps object
+
+      $map_url - reference to hash to contain URLs of maps in course
+
+      $resource_symb - reference to hash to contain symbs for
+                       resources in course
+
+      $title_ref - reference to hash containing titles for items in
+                   course
+
+      $context - examblock or dumpdocs
+
+      $cdom - course's domain
+
+      $cnum - courseID 
+
+Outputs: None
+
+Side Effects: $map_url and $resource_symb hashrefs are populated.
+
 
 =over
 
@@ -153,15 +206,17 @@
 use LONCAPA qw(:DEFAULT :match);
 
 sub create_picker {
-    my ($navmap,$context,$formname,$crstype,$blockedmaps,$blockedresources,$block) = @_;
+    my ($navmap,$context,$formname,$crstype,$blockedmaps,$blockedresources,$block,$preamble,$numhome,$uploadedfiles) = @_;
     return unless (ref($navmap));
-    my ($it,$output,$numdisc,%maps,%resources,%discussiontime,%currmaps,%currresources);
+    my ($it,$output,$numdisc,%maps,%resources,%discussiontime,%currmaps,%currresources,%files);
     $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
     if (ref($blockedmaps) eq 'HASH') {
         %currmaps = %{$blockedmaps};
     }
     if (ref($blockedresources) eq 'HASH') {
         %currresources = %{$blockedresources};
+    } elsif (ref($uploadedfiles) eq 'HASH') {
+        %files = %{$uploadedfiles};
     }
     my @checked_maps;
     my $curRes;
@@ -174,42 +229,43 @@
     my %children = ();
     my %hierarchy = ();
     my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
-    my $whitespace = 
+    my $whitespace =
         '<img src="'.$location.'/whitespace_21.gif" class="LC_docs_spacer" alt="" />';
 
-    my $onsubmit;
+    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+    my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+    my $crsprefix = &propath($cdom,$cnum).'/userfiles/';
+
+    my ($info,$display,$onsubmit,$togglebuttons);
     if ($context eq 'examblock') {
         my $maps_elem = 'docs_maps_'.$block;
         my $res_elem = 'docs_resources_'.$block;
         $onsubmit = ' onsubmit="return writeToOpener('."'$maps_elem','$res_elem'".');"';
+        $info = &mt('Items in '.lc($crstype).' for which access will be blocked.');
     }
-    my $display =
-       '<form name="'.$formname.'" action="" method="post"'.$onsubmit.'>'."\n".
-       '<p>';
-    if ($context eq 'imsexport') {
-        $display .= &mt('Choose which items you wish to export from your '.
-                        $crstype.'.');
+    if ($context eq 'dumpdocs') {
+        $info = '<span class="LC_fontsize_medium">'.
+                &mt('Choose the uploaded course items and templated pages/problems to be copied to Authoring space.').
+                '</span><br /><br />';
+        $startcount = 3 + $numhome;
+        $onsubmit = ' onsubmit="return checkUnique(document.'.$formname.',document.'.$formname.'.archive);"';
+    } elsif ($context eq 'imsexport') {
+        $info = &mt('Choose which items you wish to export from your '.$crstype.'.');
         $startcount = 5;
-    } elsif ($context eq 'examblock') {
-        $display .= &mt('Items in '.lc($crstype).' for which access will be blocked.');
     }
-    $display .= '</p>';
+    $togglebuttons = '<input type="button" value="'.&mt('check all').'" '.
+                     'onclick="javascript:checkAll(document.'.$formname.'.archive)" />'.
+                     '  <input type="button" value="'.&mt('uncheck all').'"'.
+                     ' onclick="javascript:uncheckAll(document.'.$formname.'.archive)" />';
+    $display = '<form name="'.$formname.'" action="" method="post"'.$onsubmit.'>'."\n";
     if ($context eq 'imsexport') {
-        $display .= '<div class="LC_columnSection">'."\n".
+        $display .= $info.
+                    '<div class="LC_columnSection">'."\n".
                     '<fieldset>'.
-                    '<legend>'.&mt('Content items').'</legend>'."\n";
-    }
-    $display .= 
-        '<input type="button" value="'.&mt('check all').'" '.
-        'onclick="javascript:checkAll(document.'.$formname.'.archive)" />'.
-        '  <input type="button" value="'.&mt('uncheck all').'"'.
-        ' onclick="javascript:uncheckAll(document.'.$formname.'.archive)" />';
-    if ($context eq 'imsexport') {
-        $display .= '</fieldset>';
-        %discussiontime =
-            &Apache::lonnet::dump('discussiontimes',
-                                  $env{'course.'.$env{'request.course.id'}.'.domain'},
-                                  $env{'course.'.$env{'request.course.id'}.'.num'});
+                    '<legend>'.&mt('Content items').'</legend>'."\n".
+                    $togglebuttons.
+                    '</fieldset>';
+        %discussiontime = &Apache::lonnet::dump('discussiontimes',$cdom,$cnum);
         $numdisc = keys(%discussiontime);
         if ($numdisc > 0) {
             $display .= 
@@ -221,7 +277,15 @@
                 ' onclick="javascript:uncheckAll(document.'.$formname.'.discussion)" />'.
                 '</fieldset>';
         }
-        $display .= '</div>';      
+        $display .= '</div>';
+    } elsif ($context eq 'examblock') {
+        $display .= $info.$togglebuttons;
+    } elsif ($context eq 'dumpdocs') {
+        $display .= $preamble.
+                    '<div class="LC_left_float">'.
+                    '<fieldset>'.
+                    '<legend>'.&mt('Content to copy').(' 'x4).$togglebuttons.'</legend>'.
+                    $info;
     }
     my $lastcontainer = $startcount;
     $display .= &Apache::loncommon::start_data_table()
@@ -233,12 +297,14 @@
         }
     } elsif ($context eq 'examblock') {
         $display .= '<th>'.&mt('Access blocked?').'</th>';
+    } elsif ($context eq 'dumpdocs') {
+        $display .= '<th>'.&mt('Copy?').'</th>'.
+                    '<th>'.&mt("Title in $crstype").
+                    '<th>'.&mt('Internal Identifier').'</th>'.
+                    '<th>'.&mt('Save as ...').'</th>';
     }
     $display .= &Apache::loncommon::end_data_table_header_row();
     while ($curRes = $it->next()) {
-        if (ref($curRes)) {
-             $count ++;
-        }
         if ($curRes == $it->BEGIN_MAP()) {
             $depth++;
             $parent{$depth} = $lastcontainer;
@@ -250,18 +316,29 @@
         if (ref($curRes)) {
             my $symb = $curRes->symb();
             my $ressymb = $symb;
-            if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
+            if ($context eq 'dumpdocs') {
+                next unless (($curRes->src() =~ m{^\Q/uploaded/$cdom/$cnum/\E(docs|supplemental|simplepage)}) ||
+                             ($curRes->src() =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)_\d+\.(sequence|page)}) ||
+                             ($curRes->src() eq '/res/lib/templates/simpleproblem.problem') ||
+                             ($curRes->src() =~ m{^/adm/$match_domain/$match_username/\d+/smppg}));
+            } elsif ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
                 unless ($ressymb =~ m|adm/wrapper/adm|) {
                     $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
                 }
             }
-            my $currelem = $count+$boards+$startcount;
+            $count ++;
+            my $currelem;
+            if ($context eq 'imsexport') {
+                $currelem = $count+$boards+$startcount;
+            } else {
+                $currelem = $count+$startcount;
+            }
             $display .= &Apache::loncommon::start_data_table_row().
                        '<td>'."\n".
                        '<input type="checkbox" name="archive" value="'.$count.'" ';
             if (($curRes->is_sequence()) || ($curRes->is_page())) {
                 $lastcontainer = $currelem;
-                $display .= 'onclick="javascript:checkFolder(this.form,'."'$currelem'".')" ';
+                $display .= 'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" ';
                 my $mapurl = (&Apache::lonnet::decode_symb($symb))[2];
                 if ($currmaps{$mapurl}) {
                     $display .= 'checked="checked"';
@@ -271,12 +348,15 @@
                 if ($curRes->is_problem()) {
                     $numprobs ++;
                 }
-                $display .= 'onclick="javascript:checkResource(this.form,'."'$currelem'".')" ';
+                $display .= 'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" ';
                 if ($currresources{$symb}) {
                     $display .= 'checked="checked"';
                 }
             }
             $display .= ' />'."\n";
+            if ($context eq 'dumpdocs') {
+                $display .= '</td><td valign="top">';
+            }
             for (my $i=0; $i<$depth; $i++) {
                 $display .= "$whitespace\n";
             }
@@ -303,7 +383,7 @@
                     }
                 }
             }
-            $display .= ' '.$curRes->title().'</td>'."\n";
+            $display .= ' '.$curRes->title().$whitespace.'</td>'."\n";
 
             if ($context eq 'imsexport') {
 # Existing discussion posts?
@@ -315,6 +395,35 @@
                 } elsif ($numdisc > 0) {
                     $display .= '<td> </td>'."\n";
                 }
+            } elsif ($context eq 'dumpdocs') {
+                my $src = $curRes->src();
+                my ($filepath,$title);
+                if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E}) {
+                    $filepath = &Apache::lonnet::filelocation('',$src);
+                    $filepath =~ s/\Q$crsprefix\E//;
+                    if ($curRes->is_map()) {
+                        $title = $files{$filepath};
+                    } else {
+                        $filepath =~ s{docs/}{}; 
+                        $title = $filepath;
+                        $title =~ s{^(default|\d+)/\d*/?}{};
+                    }
+                } else {
+                    $title = $curRes->title();
+                    $title =~ s{/}{_}g;
+                    $title = &clean($title);
+                    if ($src eq '/res/lib/templates/simpleproblem.problem') {
+                        my ($map,$id,$res) = &Apache::lonnet::decode_symb($symb);
+                        $map =~ s{^uploaded/$cdom/$cnum/}{};
+                        $filepath = $map.'_'.$id;
+                        $title .= '.problem';
+                    } elsif ($src =~ m{^/adm/$match_domain/$match_username/(\d+)/smppg}) {
+                        $filepath = 'smppage_'.$1.'.db';
+                        $title .= '.html';
+                    }
+                }
+                $display .= '<td>'.$filepath.'</td>'.
+                            '<td><input type="text" size="40" name="namefor_'.$count.'" id="namefor_'.$count.'" value="'.$title.'" /></td>'."\n";
             }
             $display .= &Apache::loncommon::end_data_table_row();
         }
@@ -332,24 +441,37 @@
                         ' '.&mt('Text').'</label></span></p>';
         }
     }
-    $display .= '<p>';
+    my $numcount;
     if ($context eq 'imsexport') {
         $display .= 
+           '<p>'.
            '<input type="hidden" name="finishexport" value="1" />'.
            '<input type="submit" name="exportcourse" value="'.
-           &mt('Export').'" />';
+           &mt('Export').'" /></p>';
+        $numcount = $count + $boards + $startcount;
     } elsif ($context eq 'examblock') {
         $display .=
+            '<p>'.
             '<input type="submit" name="resourceblocks" value="'.
-            &mt('Copy Choices to Main Window').'" />';
+            &mt('Copy Choices to Main Window').'" /></p>';
+        $numcount = $count + $startcount;
+    } elsif ($context eq 'dumpdocs') {
+        $display .= '</fieldset>'.
+                    '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
+                    '<div>'.
+                    '<input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype Content").'" />'.
+                    '</div>';
+        $numcount = $count + $startcount;
     }
-    $display .= '</p></form>';
-    my $numcount = $count + $boards + $startcount;
+    $display .= '</form>';
     my $scripttag = 
         &respicker_javascript($startcount,$numcount,$context,$formname,\%children,
                               \%hierarchy,\@checked_maps);
+    if ($context eq 'dumpdocs') {
+        return $scripttag.$display; 
+    }
     my ($title,$crumbs,$args);
-    if ($context eq 'imsexport') {
+    if ($context eq 'imsexport') { 
         $title = 'Export '.$crstype.' to IMS Package';
     } elsif ($context eq 'examblock') {
         $title = 'Resources with Access blocked';
@@ -361,6 +483,9 @@
     if ($context eq 'imsexport') {
         $output .= &Apache::lonhtmlcommon::breadcrumbs('IMS Export').
                    &Apache::londocs::startContentScreen('tools');
+    } elsif ($context eq 'dumpdocs') {
+         $output .= &Apache::lonhtmlcommon::breadcrumbs('Dump to Authoring Space').
+                    &Apache::londocs::startContentScreen('tools');
     }
     $output .= $display;
     if ($context eq 'examblock') {
@@ -376,6 +501,15 @@
         $checked_maps) = @_;
     return unless ((ref($children) eq 'HASH') && (ref($hierarchy) eq 'HASH')
                    && (ref($checked_maps) eq 'ARRAY'));
+    my ($elem,$nested,$nameforelem);
+    if ($context eq 'dumpdocs') {
+        $elem='((parseInt(item)-'.$startcount.')*2)+'.$startcount;
+        $nested='((parseInt(nesting[item][i])-'.$startcount.')*2)+'.$startcount;
+        $nameforelem=$elem+1;
+    } else {
+        $elem='parseInt(item)';
+        $nested='parseInt(nesting[item][i])';
+    }
     my $scripttag = <<"START";
 <script type="text/javascript">
 // <![CDATA[
@@ -400,7 +534,8 @@
 }
 
 function checkFolder(form,item) {
-    if (form.elements[item].checked == true) {
+    var elem = $elem;
+    if (form.elements[elem].checked == true) {
         containerCheck(form,item);
     } else {
         containerUncheck(form,item);
@@ -408,7 +543,8 @@
 }
 
 function checkResource(form,item) {
-    if (form.elements[item].checked == false) {
+    var elem = $elem;
+    if (form.elements[elem].checked == false) {
         containerUncheck(form,item);
     }
 }
@@ -452,12 +588,65 @@
 }
 
 EXTRA
+    } elsif ($context eq 'dumpdocs') {
+        my $blankmsg = &mt('An item selected has no filename set in the "Save as ..." column.');
+        my $dupmsg = &mt('Items selected for copying need unique filenames in the "Save as ..." column.');
+        $scripttag .= <<"EXTRA";
+
+function checkUnique(form,field) {
+    var duplicate = 0;
+    var blank = 0;
+    if (field.length > 0) {
+        for (i=0; i<field.length; i++) {
+            if (field[i].checked) {
+                var item = field[i].value;
+                var namefor = document.getElementById('namefor_'+item);
+                if (namefor) {
+                    var possval = namefor.value;
+                    if (!possval) {
+                        blank = item;
+                        break;
+                    }
+                    for (j=i+1; j<field.length; j++) {
+                        if (field[j].checked) {
+                            var curritem = field[j].value;
+                            var currnamefor = document.getElementById('namefor_'+curritem);
+                            if (currnamefor) {
+                                var currval = currnamefor.value;
+                                if (currval == possval) {
+                                    duplicate = curritem;
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                    if (duplicate) {
+                        break;
+                    }
+                }
+            }
+        }
+    }
+    if (blank) {
+        alert('$blankmsg');
+        return false;
+    }
+    if (duplicate) {
+        alert('$dupmsg');
+        return false;
+    }
+    return true;
+}
+
+EXTRA
+
     }
 
     $scripttag .= <<"END";
 
 function containerCheck(form,item) {
-    form.elements[item].checked = true;
+    var elem = $elem;
+    form.elements[elem].checked = true;
     if(Object.prototype.toString.call(parents[item]) === '[object Array]') {
         if (parents[item].length > 0) {
             for (var j=0; j<parents[item].length; j++) {
@@ -471,7 +660,7 @@
     if(Object.prototype.toString.call(nesting[item]) === '[object Array]') {
         if (nesting[item].length > 0) {
             for (var i=0; i<nesting[item].length; i++) {
-                form.elements[nesting[item][i]].checked = false;
+                var nested = $nested;
             }
         }
     }
@@ -540,7 +729,9 @@
             $outcome = &Apache::loncommon::start_page('Selection of Resources for Blocking',
                                                        undef,{'only_body' => 1,}).
                       '<h2>'.&mt('Resource Display Failed').'</h2>';  
-        } 
+        } elsif ($context eq 'dumpdocs') {
+            $outcome = '<h2>'.&mt('Dump to Authoring Space unavilable');
+        }
         $outcome .= '<div class="LC_error">';
         if ($crstype eq 'Community') {
             $outcome .= &mt('Unable to retrieve information about community contents');
@@ -548,7 +739,7 @@
             $outcome .= &mt('Unable to retrieve information about course contents');
         }
         $outcome .= '</div>';
-        if ($context eq 'imsexport') {
+        if (($context eq 'imsexport') || ($context eq 'dumpdocs')) {
             $outcome .= '<a href="/adm/coursedocs">';
             if ($crstype eq 'Community') {
                 $outcome .= &mt('Return to Community Editor');
@@ -556,7 +747,11 @@
                 $outcome .= &mt('Return to Course Editor');
             }
             $outcome .= '</a>';
-            &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
+            if ($context eq 'imsexport') {
+                &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
+            } else {
+                &Apache::lonnet::logthis('Dump to Authoring Space failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
+            }
         } elsif ($context eq 'examblock') {
             $outcome .=  '<href="javascript:window.close();">'.&mt('Close window').'</a>';         
         }
@@ -566,4 +761,44 @@
     }
 }
 
+sub clean {
+    my ($title)=@_;
+    $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
+    return $title;
+}
+
+sub enumerate_course_contents {
+    my ($navmap,$map_url,$resource_symb,$titleref,$context,$cdom,$cnum) = @_;
+    if ((ref($navmap)) && (ref($map_url) eq 'HASH') &&
+        (ref($resource_symb) eq 'HASH') && (ref($titleref) eq 'HASH')) {
+        my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
+        my $count = 0;
+        while (my $curRes = $it->next()) {
+            if (ref($curRes)) {
+                my $symb = $curRes->symb();
+                my $ressymb = $symb;
+                if ($context eq 'dumpdocs') {
+                    next unless (($curRes->src() =~ m{^\Q/uploaded/$cdom/$cnum/\E(docs|supplemental|simplepage)/}) ||
+                                 ($curRes->src() =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)_\d+\.(sequence|page)}) ||
+                                 ($curRes->src() eq '/res/lib/templates/simpleproblem.problem') ||
+                                 ($curRes->src() =~ m{^/adm/$match_domain/$match_username/\d+/smppg}));
+                } elsif ($ressymb =~ m{adm/($match_domain)/($match_username)/(\d+)/bulletinboard$}) {
+                    unless ($ressymb =~ m{adm/wrapper/adm}) {
+                        $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.
+                                   '/bulletinboard';
+                    }
+                }
+                $count ++;
+                if (($curRes->is_sequence()) || ($curRes->is_page())) {
+                    $map_url->{$count} = (&Apache::lonnet::decode_symb($symb))[2];
+                } else {
+                    $resource_symb->{$count} = $ressymb;
+                }
+                $titleref->{$count} = $curRes->title();
+            }
+        }
+    }
+    return;
+}
+
 1;
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.566 loncom/interface/londocs.pm:1.567
--- loncom/interface/londocs.pm:1.566	Sun Oct  6 20:33:45 2013
+++ loncom/interface/londocs.pm	Tue Nov 12 14:36:07 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.566 2013/10/06 20:33:45 raeburn Exp $
+# $Id: londocs.pm,v 1.567 2013/11/12 14:36:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -41,6 +41,8 @@
 use Apache::lonnavmaps;
 use Apache::lonnavdisplay();
 use Apache::lonextresedit();
+use Apache::lontemplate();
+use Apache::lonsimplepage();
 use HTML::Entities;
 use HTML::TokeParser;
 use GDBM_File;
@@ -141,7 +143,27 @@
 sub dumpcourse {
     my ($r) = @_;
     my $crstype = &Apache::loncommon::course_type();
-    $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Content to Authoring Space')."\n".
+    my ($starthash,$js);
+    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('Dump '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
               &Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' Content to Authoring Space')."\n");
     $r->print(&startContentScreen('tools'));
     my ($home,$other,%outhash)=&authorhosts();
@@ -161,118 +183,404 @@
 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
 	my $title=$env{'form.authorfolder'};
 	$title=&clean($title);
-	my %replacehash=();
-	foreach my $key (keys(%env)) {
-	    if ($key=~/^form\.namefor\_(.+)/) {
-		$replacehash{$1}=$env{$key};
-	    }
+        my ($navmap,$errormsg) =
+            &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
+        my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+        my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+        my (%maps,%resources,%titles);
+        if (!ref($navmap)) {
+            $r->print($errormsg.
+                      &endContentScreen());
+            return '';
+        } else {
+            &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'}.'/';
 	$crs=~s/\_/\//g;
-	foreach my $item (keys(%replacehash)) {
-	    my $newfilename=$title.'/'.$replacehash{$item};
-	    $newfilename=~s/\.(\w+)$//;
-	    my $ext=$1;
-	    $newfilename=&clean($newfilename);
-	    $newfilename.='.'.$ext;
-	    my @dirs=split(/\//,$newfilename);
-	    my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
-	    my $makepath=$path;
-	    my $fail=0;
-	    for (my $i=0;$i<$#dirs;$i++) {
-		$makepath.='/'.$dirs[$i];
-		unless (-e $makepath) {
-		    unless(mkdir($makepath,0777)) { $fail=1; }
-		}
-	    }
-	    $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
-	    if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
-		if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
-		    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);
-		       }
-		$fh->close();
-	    } else {
-		$fail=1;
-	    }
-	    if ($fail) {
-		$r->print('<span class="LC_error">'.&mt('fail').'</span>');
-	    } else {
-		$r->print('<span class="LC_success">'.&mt('ok').'</span>');
-	    }
-	}
+        my $mm = new File::MMagic;
+        my $prefix = "/uploaded/$cdom/$cnum/";
+        %replacehash = %tocopy;
+        foreach my $item (sort(keys(%simpleproblems))) {
+            my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
+            $newcontent{$display{$item}} = $content;
+        }
+        my $gateway = Apache::lonhtmlgateway->new('web');
+        foreach my $item (sort(keys(%simplepages))) {
+            if (ref($simplepages{$item}) eq 'HASH') {
+                my $pagetitle = $simplepages{$item}{'title'};
+                my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
+                my %contents;
+                foreach my $field (keys(%fields)) {
+                    if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
+                        my $name = $1;
+                        my $msg = $fields{$field};
+                        if ($name eq 'webreferences') {
+                            if ($msg =~ m{^https?://}) {
+                                $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
+                            }
+                        } else {
+                            $msg = &Encode::decode('utf8',$msg);
+                            $msg = $gateway->process_outgoing_html($msg,1);
+                            $contents{$name} = $msg;
+                        }
+                    } elsif ($field eq 'uploaded.photourl') {
+                        my $marker = $simplepages{$item}{marker};
+                        if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
+                            my $filepath = $1;
+                            my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
+                            if ($fname ne '') {
+                                $fname=~s/\.(\w+)$//;
+                                my $ext=$1;
+                                $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').(' '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 {
-        $r->print(&mt('Searching ...').'<br />');
-        $r->rflush();
-# Input form
-        $r->print('<form name="dumpdoc" action="" method="post">'."\n");
-	unless ($home==1) {
-	    $r->print('<div class="LC_left_float">'.
-		      '<fieldset><legend>'.
-                      &mt('Select the Authoring Space').
-                      '</legend><select name="authorspace">');
-	}
-	foreach my $key (sort(keys(%outhash))) {
-	    if ($key=~/^home_(.+)$/) {
+        my ($navmap,$errormsg) =
+            &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
+        if (!ref($navmap)) {
+            $r->print($errormsg);
+        } else {
+            $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
+            $r->rflush();
+            my ($preamble,$formname);
+            $formname = 'dumpdoc';
+	    unless ($home==1) {
+	        $preamble = '<div class="LC_left_float">'.
+		            '<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) {
-		    $r->print(
-		  '<input type="hidden" name="authorspace" value="'.$1.'" />');
+		    $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
 		} else {
-		    $r->print('<option value="'.$1.'">'.$1.' - '.
-			      &Apache::loncommon::plainname(split(/\:/,$1)).'</option>');
-		}
+		    $preamble .= '<option value="'.$user.'">'.$user.' - '.
+			         &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
+	        }
 	    }
-	}
-	unless ($home==1) {
-	    $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:' ').'</td>');
-	    if (!$title) {
-		$title=$file;
-	    } else {
-		$title=~s|/|_|g;
+	    unless ($home==1) {
+	        $preamble .= '</select></fieldset></div>'."\n";
 	    }
-	    $title=~s/\.(\w+)$//;
+	    my $title=$origcrsdata{'description'};
+	    $title=~s/[\/\s]+/\_/gs;
 	    $title=&clean($title);
-	    $title.='.'.$ext;
-	    $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
-                     .&Apache::loncommon::end_data_table_row());
-	}
-	$r->print(&Apache::loncommon::end_data_table());
-	&untiehash();
-	$r->print(
-  '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype Content").'" /></p></form>');
+	    $preamble .= '<div class="LC_left_float">'.
+                         '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
+                         '<input type="text" size="50" name="authorfolder" value="'.
+                         $title.'" />'.
+                         '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
+            my %uploadedfiles;
+	    &tiehash();
+	    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());
 }
 
+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 {
     my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
     my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,


More information about the LON-CAPA-cvs mailing list