[LON-CAPA-cvs] cvs: loncom /imspackages imsimport.pm imsimportdocs.pm imsprocessor.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Mon, 14 Feb 2005 22:46:13 -0000


This is a MIME encoded message

--raeburn1108421173
Content-Type: text/plain

raeburn		Mon Feb 14 17:46:13 2005 EDT

  Modified files:              
    /loncom/imspackages	imsimport.pm imsimportdocs.pm imsprocessor.pm 
  Log:
  User's choice of content types to import (e.g., only discussion boards, and quizzes) is now incorporated when building the LON-CAPA structure from the description of course organization in the IMS manifest file.  In addition, a .sequence file is now created for access to all questions contained in question pools.  Previously these questions were only accessible in the case of imports into CSTR.
  
  
--raeburn1108421173
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20050214174613.txt"

Index: loncom/imspackages/imsimport.pm
diff -u loncom/imspackages/imsimport.pm:1.8 loncom/imspackages/imsimport.pm:1.9
--- loncom/imspackages/imsimport.pm:1.8	Mon Dec 13 15:01:09 2004
+++ loncom/imspackages/imsimport.pm	Mon Feb 14 17:46:12 2005
@@ -374,6 +374,8 @@
         $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname);
     }
     my %resources = ();
+    my %includedres = ();
+    my %includeditems = ();
     my %items = ();
     my %hrefs = ();
     my %resinfo = ();
@@ -397,7 +399,7 @@
     my $conditions;
 
     if ($unzip_result eq 'ok') {
-        $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo);
+        $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'choose',\%includedres,\%includeditems);
         if ($manifest_result eq 'ok') {
             foreach my $res (sort keys %resources) {
                 if ($cms eq 'bb5' || $cms eq 'bb6') {
@@ -612,20 +614,16 @@
         ($cdom,$crs) = split/\//,$ENV{'form.bb_crs'};
         $chome = &Apache::lonnet::homeserver($crs,$cdom);
     } 
-    if ( defined($ENV{'form.bb_handling'}) ) {
-        $db_handling = $ENV{'form.bb_handling'};
-    }
     my $user_crs = '';
     my $user_cdom = '';
     my $user_handling = '';
     if ( defined($ENV{'form.user_crs'}) ) {
         ($user_cdom,$user_crs) = split/\//,$ENV{'form.user_crs'};
     }
-    if ( defined($ENV{'form.user_handling'}) ) {
-        $user_handling = $ENV{'form.user_handling'};
-    }
     my $seqstem = "/res/$udom/$uname/$newdir";
-    my %imports = ();
+    my %importareas = ();
+    my %includedres = ();
+    my %includeditems = ();
     my @targets = ();
     my %resources = ();
     my %items = ();
@@ -648,13 +646,13 @@
     my $tempdir = $ENV{'form.tempdir'};
 
     foreach my $area (@{$areas}) {
-        if (defined($ENV{"form.$area"}) ) {          
+        if (defined($ENV{"form.$area"}) ) {
             if ($cms eq 'angel' && $area eq 'doc') {
                 foreach (@{$$cmsmap{$cms}{$area}}) {
-                    $imports{$_} = 1;
+                    $importareas{$_} = 1;
                 }
             } else {
-                $imports{$$cmsmap{$cms}{$area}} = 1;
+                $importareas{$$cmsmap{$cms}{$area}} = 1;
             }
             if ($area eq 'board') {
                 $db_handling = $ENV{'form.db_handling'};
@@ -663,14 +661,32 @@
             }
         }
     }
-    my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo);
+
+    my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'prepare',\%includedres);
+    if ($manifest_result eq 'ok') {
+        foreach my $res (sort keys %resources) {
+            if ($importareas{$resources{$res}{type}}) {
+                $includedres{$res} = 1;
+            }
+        }
+        foreach my $itm (sort keys %items) {
+            &Apache::imsprocessor::get_imports(\%includeditems,\%items,\%resources,\%importareas,$itm);
+        }
+    }
+
+    foreach my $itm (sort keys %includeditems) {
+        &Apache::imsprocessor::get_parents(\%includeditems,\%items,$itm);
+    }
+
+    $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'build',\%includedres,\%includeditems);
     if ($manifest_result eq 'ok') {
-        &Apache::imsprocessor::target_resources(\%resources,\%imports,\@targets);
+        &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets);
 
         my @boards = ();
         my @announcements = ();
         my @quizzes = ();
         my @surveys = ();
+        my @pools = ();
         my @groups = ();
         my %messages = ();
         my @timestamp = ();
@@ -679,22 +695,25 @@
         my @topnames = ();
         my @packages = ();
 
-        &Apache::imsprocessor::process_resinfo($cms,'CSTR',$tempdir,$destdir,\%items,\%resources,\@boards,\@announcements,\@quizzes,\@surveys,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$newdir,$seqstem,\@resrcfiles,\@packages,\%hrefs,\@pages,\@sequences);
+        &Apache::imsprocessor::process_resinfo($cms,'CSTR',$tempdir,$destdir,\%items,\%resources,\@targets,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$seqstem,$seqstem,\@resrcfiles,\@packages,\%hrefs,\@pages,\@sequences);
 
-        my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$chome,$destdir,$timenow);
+        my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$chome,$destdir,$timenow,\%importareas);
    
-        &Apache::imsprocessor::build_structure($cms,'CSTR',$destdir,\%items,\%resinfo,\%resources,\%hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages);
+        &Apache::imsprocessor::build_structure($cms,'CSTR',$destdir,\%items,\%resinfo,\%resources,\@targets,\%hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages,\%includeditems);
 
-        $r->print("<h3>Step 3: Publish your new LON-CAPA materials</h3>");
+        $r->print("<h3>IMS import completed</h3>");
 
         if ($cms eq 'bb5') {
             $r->print("<font face='arial,helvetica,sans-serif'>Your IMS package has been processed successfully. A total of $total{seq} sequences, $total{page} pages, $total{board} bulletin boards, $total{quiz} quizzes, $total{surv} surveys and $total{prob} problems have been created.<br /><br />\n");
         } elsif ($cms eq 'angel') {
             $r->print("<font face='arial,helvetica,sans-serif'>Your IMS package has been processed successfully. A total of $total{seq} sequences, $total{page} pages, and $total{board} bulletin boards have been created.<br /><br />\n");
         }
-#        system (" rm -r -f $destdir/temp");
+       $r->print("Please view the imported items and use the LON-CAPA editing tools to make changes.  The sequences directory contains a file named 'Top.sequence' whichincludes links to the items found at the top level of your IMS package. From there you can follow links to display all the imported items. Alternatively, you can browse the pages, sequences, problems and resfiles directories directly. Note if you rename a file, you will need to modify any .sequence files or .page files which include a reference to the renamed file.<br /><br />The final step in the IMS import process is to publish the materials you have imported into your Construction Space so that you can use them in a course. Once your file are published, subsequent re-publication will result in the storage of information about changes between the different versions.<br /><br /><a href='/priv/".$uname."/".$newdir."'>Display new directory</a></font>"); 
+        if ($destdir =~ m-^/home/$uname/public_html/-) { 
+            system (" rm -r -f $destdir/temp");
+        }
     } elsif ($manifest_result eq 'nomanifest') {
-        $r->print("<font face='arial,helvetica,sans-serif'>Processing of your IMS package failed, because the IMS content package did not contain an IMS manifest file .");
+        $r->print("<font face='arial,helvetica,sans-serif'>Processing of your IMS package failed, because the IMS content package did not contain an IMS manifest file.</font>");
     }
 }
 
Index: loncom/imspackages/imsimportdocs.pm
diff -u loncom/imspackages/imsimportdocs.pm:1.8 loncom/imspackages/imsimportdocs.pm:1.9
--- loncom/imspackages/imsimportdocs.pm:1.8	Mon Dec 13 15:01:09 2004
+++ loncom/imspackages/imsimportdocs.pm	Mon Feb 14 17:46:12 2005
@@ -309,6 +309,8 @@
         $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname);
     }
     my %resources = ();
+    my %includedres = ();
+    my %includeditems = ();
     my %items = ();
     my %hrefs = ();
     my %resinfo = ();
@@ -331,7 +333,7 @@
                 );
 
     if ($unzip_result eq 'ok') {
-        $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo);
+        $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'choose',\%includedres,\%includeditems);
         if ($manifest_result eq 'ok') {
             foreach my $res (sort keys %resources) {
                 if ($cms eq 'bb5' || $cms eq 'bb6') {
@@ -507,7 +509,9 @@
     if ($crs =~ m/^(\d)(\d)(\d)/) {
         $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
     }
-    my %imports = ();
+    my %importareas = ();
+    my %includedres = ();
+    my %includeditems = ();
     my @targets = ();
     my %resources = ();
     my %items = ();
@@ -547,10 +551,10 @@
         if (defined($ENV{"form.$area"}) && ($ENV{'form.'.$area} ne '')) {
             if ($cms eq 'angel' && $area eq 'doc') {
                 foreach (@{$cmsmap{$cms}{$area}}) {
-                    $imports{$_} = 1;
+                    $importareas{$_} = 1;
                 }
             } else {
-                $imports{$cmsmap{$cms}{$area}} = 1;
+                $importareas{$cmsmap{$cms}{$area}} = 1;
             }
             if ($area eq 'board') {
                 $db_handling = $ENV{'form.db_handling'};
@@ -559,9 +563,35 @@
             }
         }
     }
-   
-    my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo);
+
+    my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'prepare',\%includedres,\%includeditems);
     if ($manifest_result eq 'ok') {
+        foreach my $res (sort keys %resources) {
+            if ($importareas{$resources{$res}{type}}) {
+                $includedres{$res} = 1;
+            }
+        }
+        foreach my $itm (sort keys %items) {
+            &Apache::imsprocessor::get_imports(\%includeditems,\%items,\%resources,\%importareas,$itm);
+        }
+    }
+    foreach my $itm (sort keys %includeditems) {
+        &Apache::imsprocessor::get_parents(\%includeditems,\%items,$itm);
+    }
+    foreach (sort keys %includeditems) {
+        print STDERR "Including this item - $_\n";
+    }
+    foreach (sort keys %includedres) {
+        print STDERR "Including this resource - $_\n";
+    }
+    foreach (sort keys %importareas) {
+        print STDERR "Including this area - $_\n";
+    }
+
+
+    $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'build',\%includedres,\%includeditems);
+    if ($manifest_result eq 'ok') {
+
         my @path = ($cdom,$crs,$timenow);
         my $fullpath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles';
         foreach my $item (@path) {
@@ -576,12 +606,13 @@
                 mkdir("$fullpath/$name",0770);
             }
         }
-        &Apache::imsprocessor::target_resources(\%resources,\%imports,\@targets);
+        &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets);
 
         my @boards = ();
         my @announcements = ();
         my @quizzes = ();
         my @surveys = ();
+        my @pools = ();
         my @groups = ();
         my %messages = ();
         my @timestamp = ();
@@ -590,11 +621,11 @@
         my @topnames = ();
         my @packages = ();
 
-        &Apache::imsprocessor::process_resinfo($cms,'DOCS',$tempdir,$destdir,\%items,\%resources,\@boards,\@announcements,\@quizzes,\@surveys,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$seqstem,$seqstem,\@resrcfiles,\@packages,\%hrefs,\@pages,\@sequences);
+        &Apache::imsprocessor::process_resinfo($cms,'DOCS',$tempdir,$destdir,\%items,\%resources,\@targets,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$seqstem,$seqstem,\@resrcfiles,\@packages,\%hrefs,\@pages,\@sequences);
 
-        my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$chome,$destdir,$timenow);
+        my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$chome,$destdir,$timenow,\%importareas);
 
-        &Apache::imsprocessor::build_structure($cms,'DOCS',$destdir,\%items,\%resinfo,\%resources,\%hrefs,$udom,$uname,'',$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages);
+        &Apache::imsprocessor::build_structure($cms,'DOCS',$destdir,\%items,\%resinfo,\%resources,\@targets,\%hrefs,$udom,$uname,'',$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages,\%includeditems);
  
         foreach my $item (@pages) {
             my $filename = $timenow.'/pages/'.$item;
Index: loncom/imspackages/imsprocessor.pm
diff -u loncom/imspackages/imsprocessor.pm:1.13 loncom/imspackages/imsprocessor.pm:1.14
--- loncom/imspackages/imsprocessor.pm:1.13	Thu Dec 23 13:38:45 2004
+++ loncom/imspackages/imsprocessor.pm	Mon Feb 14 17:46:12 2005
@@ -141,7 +141,7 @@
 }
 
 sub process_manifest {
-    my ($cms,$tempdir,$resources,$items,$hrefs,$resinfo) = @_;
+    my ($cms,$tempdir,$resources,$items,$hrefs,$resinfo,$phase,$includedres,$includeditems) = @_;
     my %toc = (
               bb6 => 'organization',
               bb5 => 'tableofcontents',
@@ -165,6 +165,8 @@
         $$resources{'toplevel'}{type} = "FOLDER";
     } elsif ($cms eq 'bb5' || $cms eq 'bb6') {
         $$resources{'toplevel'}{type} = 'resource/x-bb-document';
+    } else {
+        $$resources{'toplevel'}{type} = 'webcontent';
     }
 
     unless (-e "$tempdir/imsmanifest.xml") {
@@ -192,84 +194,88 @@
                         $num --; 
                     }
                     if (("@state" eq $searchstr) && (@state > 3)) {
-                        $itm = $attr->{identifier};              
-                        %{$$items{$itm}} = ();
-                        $$items{$itm}{contentscount} = 0;
-                        if ($cms eq 'bb5' || $cms eq 'bb6') {
-                            $$items{$itm}{resnum} = $attr->{identifierref};
-                            if ($cms eq 'bb5') {
-                                $$items{$itm}{title} = $attr->{title};
-                            }
-                        } elsif ($cms eq 'angel') {
-                            if ($attr->{identifierref} =~ m/^res(.+)$/) {
-                                $$items{$itm}{resnum} = $1;
-                            }
-                        }
-                        unless (defined(%{$$resources{$$items{$itm}{resnum}}}) ) {
-                            %{$$resources{$$items{$itm}{resnum}}} = ();
-                        }
-                        $$resources{$$items{$itm}{resnum}}{revitm} = $itm;
-
-                        if ($start > @seq) {
-                            unless ($lastitem eq '') {
-                                push @seq, $lastitem;
-                                unless ( defined($contents{$seq[-1]}) ) {
-                                    @{$contents{$seq[-1]}} = ();
+                        $itm = $attr->{identifier};
+                        if ($$includeditems{$itm} || $phase ne 'build') {              
+                            %{$$items{$itm}} = ();
+                            $$items{$itm}{contentscount} = 0;
+                            if ($cms eq 'bb5' || $cms eq 'bb6') {
+                                $$items{$itm}{resnum} = $attr->{identifierref};
+                                if ($cms eq 'bb5') {
+                                    $$items{$itm}{title} = $attr->{title};
+                                }
+                            } elsif ($cms eq 'angel') {
+                                if ($attr->{identifierref} =~ m/^res(.+)$/) {
+                                    $$items{$itm}{resnum} = $1;
                                 }
-                                push @{$contents{$seq[-1]}},$itm;
-                                $$items{$itm}{parentseq} = $seq[-1];
                             }
-                        }
-                        elsif ($start < @seq) {
-                            my $diff = @seq - $start;
-                            while ($diff > 0) {
-                                pop @seq;
-                                $diff --;
+                            unless (defined(%{$$resources{$$items{$itm}{resnum}}}) ) {
+                                %{$$resources{$$items{$itm}{resnum}}} = ();
                             }
-                            if (@seq) {
+                            $$resources{$$items{$itm}{resnum}}{revitm} = $itm;
+                            if ($start > @seq) {
+                                unless ($lastitem eq '') {
+                                    push @seq, $lastitem;
+                                    unless ( defined($contents{$seq[-1]}) ) {
+                                        @{$contents{$seq[-1]}} = ();
+                                    }
+                                    push @{$contents{$seq[-1]}},$itm;
+                                    $$items{$itm}{parentseq} = $seq[-1];
+                                }
+                            } elsif ($start < @seq) {
+                                my $diff = @seq - $start;
+                                while ($diff > 0) {
+                                    pop @seq;
+                                    $diff --;
+                                }
+                                if (@seq) {
+                                    push @{$contents{$seq[-1]}}, $itm;
+                                }
+                            } else {
                                 push @{$contents{$seq[-1]}}, $itm;
                             }
-                        } else {
-                            push @{$contents{$seq[-1]}}, $itm;
-                        }
-                        my $path;
-                        if (@seq > 1) {
-                            $path = join(',',@seq);
-                        } elsif (@seq > 0) {
-                            $path = $seq[0];
-                        }
-                        $$items{$itm}{filepath} = $path;
-                        if ($cms eq 'bb5' || $cms eq 'bb6') {
-                            if ($$items{$itm}{filepath} eq 'Top') {
-                                $$items{$itm}{resnum} = $itm;
-                                $$resources{$$items{$itm}{resnum}}{type} = 'resource/x-bb-document';
-                                $$resources{$$items{$itm}{resnum}}{revitm} = $itm;
-                                $$resinfo{$$items{$itm}{resnum}}{'isfolder'} = 'true';
+                            my $path;
+                            if (@seq > 1) {
+                                $path = join(',',@seq);
+                            } elsif (@seq > 0) {
+                                $path = $seq[0];
                             }
+                            $$items{$itm}{filepath} = $path;
+                            if ($cms eq 'bb5' || $cms eq 'bb6') {
+                                if ($$items{$itm}{filepath} eq 'Top') {
+                                    $$items{$itm}{resnum} = $itm;
+                                    $$resources{$$items{$itm}{resnum}}{type} = 'resource/x-bb-document';
+                                    $$resources{$$items{$itm}{resnum}}{revitm} = $itm;
+                                    $$resinfo{$$items{$itm}{resnum}}{'isfolder'} = 'true';
+                                }
+                            }
+                            $$items{$seq[-1]}{contentscount} ++;
+                            $lastitem = $itm;
                         }
-                        $$items{$seq[-1]}{contentscount} ++;
-                        $lastitem = $itm;
                     }
                 } elsif ("@state" eq "manifest resources resource" ) {
                     $identifier = $attr->{identifier};
-                    if ($cms eq 'bb5' || $cms eq 'bb6') {
-                        $$resources{$identifier}{file} = $attr->{file};
-                        $$resources{$identifier}{type} = $attr->{type};
-                    } elsif ($cms eq 'angel') {
-                        $identifier = substr($identifier,3);
-                        if ($attr->{href} =~ m-^_assoc/$identifier/(.+)$-) {
-                            $$resources{$identifier}{file} = $1;
+                    if ($$includedres{$identifier} || $phase ne 'build') { 
+                        if ($cms eq 'bb5' || $cms eq 'bb6') {
+                            $$resources{$identifier}{file} = $attr->{file};
+                            $$resources{$identifier}{type} = $attr->{type};
+                        } elsif ($cms eq 'angel') {
+                            $identifier = substr($identifier,3);
+                            if ($attr->{href} =~ m-^_assoc/$identifier/(.+)$-) {
+                                $$resources{$identifier}{file} = $1;
+                            }
                         }
+                        @{$$hrefs{$identifier}} = ();
                     }
-                    @{$$hrefs{$identifier}} = ();
                 } elsif ("@state" eq "manifest resources resource file") {
-                    if ($cms eq 'bb5' || $cms eq 'bb6') {
-                        push @{$$hrefs{$identifier}},$attr->{href};
-                    } elsif ($cms eq 'angel') {
-                        if ($attr->{href} =~ m/^_assoc\\$identifier\\(.+)$/) {
-                            push @{$$hrefs{$identifier}},$1;
-                        } elsif ($attr->{href} =~ m/^Icons\\icon(\w+)\.gif/) {
-                            $$resources{$identifier}{type} = $1;
+                    if ($$includedres{$identifier} || $phase ne 'build') {
+                        if ($cms eq 'bb5' || $cms eq 'bb6') {
+                            push @{$$hrefs{$identifier}},$attr->{href};
+                        } elsif ($cms eq 'angel') {
+                            if ($attr->{href} =~ m/^_assoc\\$identifier\\(.+)$/) {
+                                push @{$$hrefs{$identifier}},$1;
+                            } elsif ($attr->{href} =~ m/^Icons\\icon(\w+)\.gif/) {
+                                $$resources{$identifier}{type} = $1;
+                            }
                         }
                     }
                 }
@@ -278,8 +284,10 @@
             [sub {
                 my ($text) = @_;
                 if ($state[0] eq "manifest" && $state[1] eq "organizations" && $state[2] eq $toc{$cms} && $state[-1] eq "title") {
-                    if ($cms eq 'angel' || $cms eq 'bb6') {
-                        $$items{$itm}{title} = $text;
+                    if ($$includeditems{$itm} || $phase ne 'build') {
+                        if ($cms eq 'angel' || $cms eq 'bb6') {
+                            $$items{$itm}{title} = $text;
+                        }
                     }
                 }
               }, "dtext"],
@@ -298,6 +306,35 @@
     return 'ok' ;
 }
 
+sub get_imports {
+    my ($includeditems,$items,$resources,$importareas,$itm) = @_;
+    if (exists($$items{$itm}{resnum})) {
+        if ($$importareas{$$resources{$$items{$itm}{resnum}}{type}}) {
+            unless (exists($$includeditems{$itm})) {
+                $$includeditems{$itm} = 1;
+            }
+        }
+    }
+    if ($$items{$itm}{contentscount} > 0) {
+        foreach my $child (@{$$items{$itm}{contents}}) {
+            &get_imports($includeditems,$items,$resources,$importareas,$child);
+        }
+    }
+}
+
+sub get_parents {
+    my ($includeditems,$items,$itm) = @_;
+    my @pathitems = ();
+    if ($$items{$itm}{filepath} =~ m/,/) {
+       @pathitems = split/,/,$$items{$itm}{filepath};
+    } else {
+       $pathitems[0] = $$items{$itm}{filepath};
+    }
+    foreach (@pathitems) {
+        $$includeditems{$_} = 1;
+    }
+}
+
 sub target_resources {
     my ($resources,$oktypes,$targets) = @_;
     foreach my $key (keys %{$resources}) {
@@ -334,28 +371,30 @@
             mkdir("$destdir/resfiles",0770);
         }
         foreach my $key (sort keys %{$hrefs}) {
-            foreach my $file (@{$$hrefs{$key}}) {
-                $file =~ s-\\-/-g;
-                if ( ($cms eq 'angel' && $file ne 'pg'.$key.'.htm') || ($cms eq 'bb5') || ($cms eq 'bb6') ) {
-                    if (!-e "$destdir/resfiles/$key") {
-                        mkdir("$destdir/resfiles/$key",0770);
-                    }
-
-                    my $filepath = $file;
-                    my $front = '';
-                    while ($filepath =~ m-(\w+)/(.+)-) {
-                        $front .= $1.'/';
-                        $filepath = $2;
-                        my $fulldir = "$destdir/resfiles/$key/$front";
-                        chop($fulldir);
-                        if (!-e "$fulldir") {
-                            mkdir("$fulldir",0770);
+            if (grep/^$key$/,@{$targets}) {
+                foreach my $file (@{$$hrefs{$key}}) {
+                    $file =~ s-\\-/-g;
+                    if ( ($cms eq 'angel' && $file ne 'pg'.$key.'.htm') || ($cms eq 'bb5') || ($cms eq 'bb6') ) {
+                        if (!-e "$destdir/resfiles/$key") {
+                            mkdir("$destdir/resfiles/$key",0770);
+                        }
+
+                        my $filepath = $file;
+                        my $front = '';
+                        while ($filepath =~ m-(\w+)/(.+)-) {
+                            $front .= $1.'/';
+                            $filepath = $2;
+                            my $fulldir = "$destdir/resfiles/$key/$front";
+                            chop($fulldir);
+                            if (!-e "$fulldir") {
+                                mkdir("$fulldir",0770);
+                            }
+                        }
+                        if ($cms eq 'angel') {
+                            rename("$tempdir/_assoc/$key/$file","$destdir/resfiles/$key/$file");
+                        } elsif ($cms eq 'bb5' || $cms eq 'bb6') {
+                            rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file");
                         }
-                    }
-                    if ($cms eq 'angel') {
-                        rename("$tempdir/_assoc/$key/$file","$destdir/resfiles/$key/$file");
-                    } elsif ($cms eq 'bb5' || $cms eq 'bb6') {
-                        rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file");
                     }
                 }
             }
@@ -363,38 +402,8 @@
     }
 }
 
-sub process_coursefile {
-    my ($crs,$cdom,$chome,$file,$source)=@_;
-    my $fetchresult = '';
-    my $fpath = '';
-    my $fname = $file;
-    ($fpath,$fname) = ($file =~ m/^(.*)\/([^\/])$/);
-    $fpath=$cdom.'/'.$crs.'/'.$fpath;
-    my $filepath=$Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles';
-    unless ($fpath eq '') {
-        my @parts=split(/\//,$fpath);
-        foreach my $part (@parts) {
-            $filepath.= '/'.$part;
-            if ((-e $filepath)!=1) {
-                mkdir($filepath,0777);
-            }
-        }
-    }
-    if ($source eq '') {
-        $fetchresult eq 'no source file provided';
-    } else {
-        my $destination = $filepath.'/'.$fname;
-        rename($source,$destination);
-        $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$cdom.'/'.$crs.'/'.$file,$chome);
-        unless ($fetchresult eq 'ok') {
-            &Apache::lonnet::logthis('Failed to transfer '.$cdom.'/'.$crs.'/'.$fname.' to host '.$chome.': '.$fetchresult);
-        }
-    }
-    return $fetchresult;
-}
-
 sub process_resinfo {
-    my ($cms,$context,$docroot,$destdir,$items,$resources,$boards,$announcements,$quizzes,$surveys,$groups,$messages,$timestamp,$boardnum,$resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,$total,$dirname,$seqstem,$resrcfiles,$packages,$hrefs,$pagesfiles,$sequencesfiles) = @_;
+    my ($cms,$context,$docroot,$destdir,$items,$resources,$targets,$boards,$announcements,$quizzes,$surveys,$pools,$groups,$messages,$timestamp,$boardnum,$resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,$total,$dirname,$seqstem,$resrcfiles,$packages,$hrefs,$pagesfiles,$sequencesfiles) = @_;
     my $board_id = time;
     my $board_count = 0;
     my $announce_handling = 'include';
@@ -402,9 +411,15 @@
     if ($crs =~ m/^(\d)(\d)(\d)/) {
         $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
     }
+    if ($context eq 'CSTR') {
+        if (!-e "$destdir/resfiles") {
+            mkdir("$destdir/resfiles",0770);
+        }
+    }
     if ($cms eq 'angel') {
         my $currboard = '';
         foreach my $key (sort keys %{$resources}) {
+          if (grep/^$key$/,@{$targets}) {
             if ($$resources{$key}{type} eq "BOARD") {
                 push @{$boards}, $key;
                 $$boardnum{$$resources{$key}{revitm}} = $board_count;
@@ -429,9 +444,11 @@
             } elsif ($$resources{$key}{type} eq "DROPBOX") {
                 %{$$resinfo{$key}} = ();
             }
+          }
         }
     } elsif ($cms eq 'bb5' || $cms eq 'bb6') {
         foreach my $key (sort keys %{$resources}) {
+          if (grep/^$key$/,@{$targets}) {
             if ($$resources{$key}{type} eq "resource/x-bb-document") {
                 unless ($$items{$$resources{$key}{revitm}}{filepath} eq 'Top') {
                     %{$$resinfo{$key}} = ();
@@ -455,6 +472,7 @@
             } elsif ($$resources{$key}{type} eq "assessment/x-bb-pool") {
                 %{$$resinfo{$key}} = ();
                 &process_assessment($context,$key,$docroot,'pool',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles);
+                push @{$pools}, $key;
             } elsif ($$resources{$key}{type} eq "assessment/x-bb-quiz") {
                 %{$$resinfo{$key}} = ();
                 &process_assessment($context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles);
@@ -479,6 +497,7 @@
                     &process_announce($key,$docroot,$destdir,\%{$$resinfo{$key}},$resinfo,$seqstem,$resrcfiles);
                 }
             }
+          }
         }
         if (@{$announcements}) {
             $$items{'Top'}{'contentscount'} ++;
@@ -492,20 +511,25 @@
         if (@{$surveys}) {
             $$items{'Top'}{'contentscount'} ++;
         }
+        if (@{$pools}) {
+            $$items{'Top'}{'contentscount'} ++;
+        }
     }
 
     $$total{'board'} = $board_count;
     $$total{'quiz'} = @{$quizzes};
     $$total{'surv'} = @{$surveys};
+    $$total{'pool'} = @{$pools};
 }
 
 sub build_structure {
-    my ($cms,$context,$destdir,$items,$resinfo,$resources,$hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,$timestamp,$total,$boards,$announcements,$quizzes,$surveys,$boardnum,$pagesfiles,$seqfiles,$topurls,$topnames,$packages) = @_;
+    my ($cms,$context,$destdir,$items,$resinfo,$resources,$targets,$hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,$timestamp,$total,$boards,$announcements,$quizzes,$surveys,$pools,$boardnum,$pagesfiles,$seqfiles,$topurls,$topnames,$packages,$includeditems) = @_;
     my %flag = ();
     my %count = ();
     my %pagecontents = ();
     my %seqtext = ();
     my $topnum = 0;
+    my $topspecials = @$announcements + @$boards + @$quizzes + @$surveys + @$pools;
 
     if (!-e "$destdir") {
         mkdir("$destdir",0755);
@@ -537,6 +561,7 @@
     }
 
     foreach my $key (sort keys %{$items}) {
+      if ($$includeditems{$key}) {
         %{$flag{$key}} = (
                           page => 0,
                           seq => 0,
@@ -562,9 +587,17 @@
                 $seqtext{$key} = "<map>\n";
             }
             if ($$items{$key}{contentscount} == 0) {
-                $seqtext{$key} .= qq|<resource id="$curr_id" src="" type="start"></resource>
+	        if ($key eq 'Top') {
+                    unless ($topspecials) {
+                        $seqtext{$key} .= qq|<resource id="$curr_id" src="" type="start"></resource>
+<link from="$curr_id" to="$next_id" index="$curr_id"></link>
+<resource id="$next_id" src="" type="finish"></resource>\n|;
+                    }
+                } else {
+                    $seqtext{$key} .= qq|<resource id="$curr_id" src="" type="start"></resource>
 <link from="$curr_id" to="$next_id" index="$curr_id"></link>
 <resource id="$next_id" src="" type="finish"></resource>\n|;
+                }
             } else {
                 my $contcount = @{$$items{$key}{contents}};
                 my $contitem = $$items{$key}{contents}[0];
@@ -588,8 +621,16 @@
                 }
                 if ($contcount == 1) {
                     $seqtext{$key} .= qq|></resource>
-<link from="$curr_id" to="$next_id" index="$curr_id"></link>
+<link from="$curr_id" to="$next_id" index="$curr_id"></link>|;
+                    if ($key eq 'Top') {
+                        unless ($topspecials) {
+                            $seqtext{$key} .= qq|
 <resource id="$next_id" src="" type="finish"></resource>\n|;
+                        }
+                    } else {
+                        $seqtext{$key} .= qq|
+<resource id="$next_id" src="" type="finish"></resource>\n|;
+                    }
                 } else {
                     if ($contcount > 2 ) {
                         for (my $i=1; $i<$contcount-1; $i++) {
@@ -663,6 +704,7 @@
             $$total{page} += $count{$key}{page};
         }
         $$total{seq} += $count{$key}{seq};
+      }
     }
     $topnum += ($count{'Top'}{page} + $count{'Top'}{seq});
 
@@ -679,6 +721,9 @@
         if (@{$surveys} > 0)  {
             &process_specials($context,'surveys',$surveys,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames);
         }
+        if (@{$pools} > 0)  {
+            &process_specials($context,'pools',$pools,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames);
+        }
         $seqtext{'Top'} .= "</map>\n";
         open(TOPFILE,">$destdir/sequences/Top.sequence");
         print TOPFILE $seqtext{'Top'};
@@ -815,12 +860,14 @@
                   quizzes => 'quizzes',
                   surveys => 'surveys',
                   announcements => 'announcements',
+                  pools => 'pools'
                   );
     my %seqtitles = (
                   boards => 'Course Bulletin Boards',
                   quizzes => 'Course Quizzes',
                   surveys => 'Course Surveys',
                   announcements => 'Course Announcements',
+                  pools => 'Course Question Pools'
                    );
     $$topnum ++;
 
@@ -862,6 +909,8 @@
         $specialsrc = "/adm/$udom/$uname/$$timestamp[0]/bulletinboard";
     } elsif ($type eq 'announcements') {
         $specialsrc = "$seqstem/resfiles/$$specials[0].html";
+    } elsif ($type eq 'pools') {
+        $specialsrc = "$seqstem/sequences/$$specials[0].sequence";
     } else {
         $specialsrc = "$seqstem/pages/$$specials[0].page";
     }
@@ -1509,10 +1558,6 @@
     my @allids = ();
     my %allanswers = ();
     my %allchoices = ();
-    my $resdir = '';
-    if ($docroot =~ m|public_html/(.+)$|) {
-        $resdir = $1;
-    }
     my $id; # the current question ID
     my $answer_id; # the current answer ID
     my %toptag = ( pool => 'POOL',
@@ -1697,7 +1742,7 @@
         ($cdom,$cnum) = split/_/,$cid;
     }
     if ($context eq 'CSTR') {
-        $probsrc="/res/$udom/$uname/$resdir/problems/$dirtitle/$allids[0].problem";
+        $probsrc="/res/$udom/$uname/$dirname/problems/$dirtitle/$allids[0].problem";
     }
     print $fh qq|<resource id="1" src="$probsrc" type="start" title="question_0001"></resource>|;
     if (@allids == 1) {
@@ -1713,7 +1758,7 @@
             $curr_id = $j;
             $next_id = $curr_id + 1;
             if ($context eq 'CSTR') {
-                $probsrc = "/res/$udom/$uname/$resdir/problems/$dirtitle/$allids[$j].problem";
+                $probsrc = "/res/$udom/$uname/$dirname/problems/$dirtitle/$allids[$j].problem";
             }
             print $fh qq|
 <link from="$curr_id" to="$next_id" index="$curr_id"></link>
@@ -2177,7 +2222,8 @@
     my $xmlfile = $docroot.'/'.$res.".dat";
     my $destresdir = $destdir;
     if ($context eq 'CSTR') {
-        $destresdir =~ s|/home/$user/public_html/|/res/$dom/$user/|;
+#        $destresdir =~ s|/home/$user/public_html/|/res/$dom/$user/|;
+        $destresdir =~ s|/home/$user/public_html/|/priv/$user/|;
     } elsif ($context eq 'DOCS') {
         $destresdir =~ s|^/home/httpd/html/userfiles|/uploaded|;
     }
@@ -2355,37 +2401,40 @@
         }
     }
 
-    open(FILE,">$destdir/resfiles/$res.html");
-    push @{$resrcfiles}, "$res.html";
-    my $htmldoc = 0;
-#    if ($$settings{maindata}{text} =~ m-&lt;(html|HTML)>.+&lt;\\(html|HTML)-) {
-    if ($$settings{maindata}{text} =~ m-<(html|HTML)>-) {
-        $htmldoc = 1;
-    }
-    unless ($htmldoc) {
-        print FILE qq|<html>
+    if (!open(FILE,">$destdir/resfiles/$res.html")) {
+        &Apache::lonnet::logthis("IMS import error: Cannot open file - $destdir/resfiles/$res.html - $!");
+    } else {
+        push @{$resrcfiles}, "$res.html";
+        my $htmldoc = 0;
+#        if ($$settings{maindata}{text} =~ m-&lt;(html|HTML)>.+&lt;\\(html|HTML)-) {
+        if ($$settings{maindata}{text} =~ m-<(html|HTML)>-) {
+            $htmldoc = 1;
+        }
+        unless ($htmldoc) {
+            print FILE qq|<html>
 <head>
 <title>$$settings{title}</title>
 </head>
 <body bgcolor='#ffffff'>
 $fontcol
 |;
-    }
-    unless ($$settings{title} eq '') { 
-        print FILE qq|$$settings{title}<br/><br/>\n|;
-    }
-    print FILE qq|
-$$settings{maindata}{text}
-$linktag|;
-    unless ($htmldoc) {
-        if (defined($$settings{maindata}{textcolor})) {
-            print FILE qq|</font>|;
+        }
+        unless ($$settings{title} eq '') { 
+            print FILE qq|$$settings{title}<br/><br/>\n|;
         }
         print FILE qq|
+$$settings{maindata}{text}
+$linktag|;
+        unless ($htmldoc) {
+            if (defined($$settings{maindata}{textcolor})) {
+                print FILE qq|</font>|;
+            }
+            print FILE qq|
   </body>
  </html>|;
+        }
+        close(FILE);
     }
-    close(FILE);
 }
 
 

--raeburn1108421173--