--- loncom/imspackages/imsprocessor.pm	2008/08/26 01:35:15	1.45
+++ loncom/imspackages/imsprocessor.pm	2011/11/03 17:54:53	1.50
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Processor for IMS Packages
 #
-# $Id: imsprocessor.pm,v 1.45 2008/08/26 01:35:15 www Exp $
+# $Id: imsprocessor.pm,v 1.50 2011/11/03 17:54:53 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -62,14 +62,14 @@ sub ims_config {
                 users => 'course/x-bb-user',
                 );
     $$cmsmap{bb6}{conference} = 'resource/x-bb-conference';
-    %{$$cmsmap{angel}} =  (
+    %{$$cmsmap{angel5}} =  (
                 board => 'BOARD',
                 extlink => 'LINK',
                 msg => 'MESSAGE',
                 quiz => 'QUIZ',
                 survey => 'FORM',
                 );
-    @{$$cmsmap{angel}{doc}} = ('FILE','PAGE');
+    @{$$cmsmap{angel5}{doc}} = ('FILE','PAGE');
     %{$$cmsmap{webctce4}} = (
                 quiz => 'webctquiz',
                 survey => 'webctsurvey',
@@ -170,7 +170,7 @@ sub process_manifest {
     my %toc = (
               bb6 => 'organization',
               bb5 => 'tableofcontents',
-              angel => 'organization',
+              angel5 => 'organization',
               webctce4 => 'organization',
               webctvista4 => 'organization'
               );
@@ -183,7 +183,7 @@ sub process_manifest {
                                   revitm => 'Top'
                                  );
  
-    if ($cms eq 'angel') {
+    if ($cms eq 'angel5') {
         $$resources{'toplevel'}{type} = "FOLDER";
     } elsif ($cms eq 'bb5' || $cms eq 'bb6') {
         $$resources{'toplevel'}{type} = 'resource/x-bb-document';
@@ -230,7 +230,7 @@ sub parse_manifest {
                                 if ($cms eq 'bb5') {
                                     $$items{$itm}{title} = $attr->{title};
                                 }
-                            } elsif ($cms eq 'angel') {
+                            } elsif ($cms eq 'angel5') {
                                 if ($attr->{identifierref} =~ m/^res(.+)$/) {
                                     $$items{$itm}{resnum} = $1;
                                 }
@@ -298,7 +298,7 @@ sub parse_manifest {
                         } elsif ($cms eq 'webctvista4') {
                             $$resources{$identifier}{type} = $attr->{type};
                             $$resources{$identifier}{'webct:coType'} = $attr->{'webct:coType'};
-                        } elsif ($cms eq 'angel') {
+                        } elsif ($cms eq 'angel5') {
                             $identifier = substr($identifier,3);
                             if ($attr->{href} =~ m-^_assoc/$identifier/(.+)$-) {
                                 $$resources{$identifier}{file} = $1;
@@ -327,7 +327,7 @@ sub parse_manifest {
                                                 $items,$resources,$resinfo,
                                                 $hrefs,$currseqref);
                             }
-                        } elsif ($cms eq 'angel') {
+                        } elsif ($cms eq 'angel5') {
                             if ($attr->{href} =~ m/^_assoc\\$identifier\\(.+)$/) {
                                 push @{$$hrefs{$identifier}},$1;
                             } elsif ($attr->{href} =~ m/^Icons\\icon(\w+)\.gif/) {
@@ -351,7 +351,7 @@ sub parse_manifest {
                 }
                 if ($state[0] eq "manifest" && $state[1] eq "organizations" && $state[2] eq $$toc{$cms} && $state[-1] eq "title") {
                     if ($$includeditems{$itm} || $phase ne 'build') {
-                        if ($cms eq 'angel' || $cms eq 'bb6' || $cms eq 'webctvista4') {
+                        if ($cms eq 'angel5' || $cms eq 'bb6' || $cms eq 'webctvista4') {
                             $$items{$itm}{title} = $text;
                         }
                         if ($cms eq 'webctce4') {
@@ -426,7 +426,7 @@ sub copy_resources {
                     }
                     my $filename = '';
                     my $fpath = $timenow.'/resfiles/'.$key.'/';
-                    if ($cms eq 'angel') {
+                    if ($cms eq 'angel5') {
                         if ($file eq 'pg'.$key.'.htm') {
                             next;
                         }
@@ -456,7 +456,7 @@ sub copy_resources {
             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 ( ($cms eq 'angel5' && $file ne 'pg'.$key.'.htm') || ($cms eq 'bb5') || ($cms eq 'bb6')) {
                         if (!-e "$destdir/resfiles/$key") {
                             mkdir("$destdir/resfiles/$key",0770);
                         }
@@ -472,7 +472,7 @@ sub copy_resources {
                             }
                         }
                         my $renameres;
-                        if ($cms eq 'angel') {
+                        if ($cms eq 'angel5') {
                             $renameres = rename("$tempdir/_assoc/$key/$file","$destdir/resfiles/$key/$file");
                         } elsif ($cms eq 'bb5' || $cms eq 'bb6') {
                             $renameres = rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file");
@@ -537,7 +537,7 @@ sub process_resinfo {
             mkdir("$destdir/resfiles",0770);
         }
     }
-    if ($cms eq 'angel') {
+    if ($cms eq 'angel5') {
         my $currboard = '';
         foreach my $key (sort keys %{$resources}) {
           if (grep/^$key$/,@{$targets}) {
@@ -679,10 +679,11 @@ sub process_resinfo {
                 $cid = $env{'request.course.id'};
             }
             my $destresdir = $destdir;
+            my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
             if ($context eq 'CSTR') {
-                $destresdir =~ s|/home/$uname/public_html/|/res/$udom/$uname/|;
+                $destresdir =~ s{^\Q$londocroot/priv/\E}{/res/};
             } elsif ($context eq 'DOCS') {
-                $destresdir =~ s|^/home/httpd/html/userfiles|/uploaded|;
+                $destresdir =~ s{^\Q$londocroot/userfiles\E}{/uploaded};
             }
             foreach my $res (sort(keys(%allquestions))) {
                 my $parent = $allquestions{$res};
@@ -764,7 +765,7 @@ sub build_structure {
         $seqtitle =~ s|/+|_|g;
         $seqtitle =~ s/\s+/_/g;
         $seqtitle .= '_'.$key;
-        if (($cms eq 'angel' && $type eq "FOLDER") || (($cms eq 'bb5' || $cms eq 'bb6') && $$resinfo{$resnum}{'isfolder'} eq "true") && (($type eq "resource/x-bb-document") || ($type eq "resource/x-bb-staffinfo") || ($type eq "resource/x-bb-externallink")) || ($cms eq 'webctce4' &&  $contentscount > 0)) {
+        if (($cms eq 'angel5' && $type eq "FOLDER") || (($cms eq 'bb5' || $cms eq 'bb6') && $$resinfo{$resnum}{'isfolder'} eq "true") && (($type eq "resource/x-bb-document") || ($type eq "resource/x-bb-staffinfo") || ($type eq "resource/x-bb-externallink")) || ($cms eq 'webctce4' &&  $contentscount > 0)) {
             unless (($cms eq 'bb5') && $key eq 'Top') {
                 $seqtext{$key} = "<map>\n";
             }
@@ -1007,7 +1008,7 @@ sub build_structure {
 sub make_structure {
     my ($cms,$key,$srcstem,$flag,$count,$timestamp,$boardnum,$hrefs,$pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$randompick,$title) = @_;
     my $src ='';
-    if (($cms eq 'angel' && $type eq 'FOLDER') || (($cms eq 'bb5' || $cms eq 'bb6') && (($$resinfo{$res}{'isfolder'} eq 'true') || $key eq 'Top')) || ($cms eq 'webctce4' && $contitemcount > 0)) {
+    if (($cms eq 'angel5' && $type eq 'FOLDER') || (($cms eq 'bb5' || $cms eq 'bb6') && (($$resinfo{$res}{'isfolder'} eq 'true') || $key eq 'Top')) || ($cms eq 'webctce4' && $contitemcount > 0)) {
         $src = $srcstem.'/sequences/'.$contitem.'.sequence';
         if ($cms eq 'webctce4') {
             $title =~ s|/+|_|g;
@@ -1023,12 +1024,12 @@ sub make_structure {
         $$flag{$key}{page} = 0;
         $$flag{$key}{seq} = 1;
         $$count{$key}{seq} ++;
-    } elsif ($cms eq 'angel' && $type eq 'BOARD') {
+    } elsif ($cms eq 'angel5' && $type eq 'BOARD') {
         $src = '/adm/'.$cdom.'/'.$uname.'/'.$$timestamp[$$boardnum{$res}].'/bulletinboard'; 
         $$flag{$key}{page} = 0;
         $$flag{$key}{board} = 1;
         $$count{$key}{board} ++;
-    } elsif ($cms eq 'angel' && $type eq "FILE") {
+    } elsif ($cms eq 'angel5' && $type eq "FILE") {
         foreach my $file (@{$$hrefs{$res}}) {
             unless ($file eq 'pg'.$res.'.htm') {
                 $src = $srcstem.'/resfiles/'.$res.'/'.$file;
@@ -1036,7 +1037,7 @@ sub make_structure {
         }
         $$flag{$key}{page} = 0;
         $$flag{$key}{file} = 1;
-    } elsif ($cms eq 'angel' && (($type eq "PAGE") || ($type eq "LINK")) )  {
+    } elsif ($cms eq 'angel5' && (($type eq "PAGE") || ($type eq "LINK")) )  {
         if ($$flag{$key}{page}) {
             if ($$count{$key}{page} == -1) {
                 &Apache::lonnet::logthis("IMS Angel import error in array index for page: value = -1, resource is $key, type is $type.");
@@ -1117,7 +1118,7 @@ sub process_specials {
                   pools => 'pools'
                   );
     my %seqtitles = (
-                  boards => 'Course Bulletin Boards',
+                  boards => 'Course Discussion Boards',
                   quizzes => 'Course Quizzes',
                   surveys => 'Course Surveys',
                   announcements => 'Course Announcements',
@@ -1458,7 +1459,7 @@ sub process_staff {
             <font face="arial" size="2"><b>Office Hours:</b></font>
           </td>
           <td>
-            <font face=arial size=2>$$settings{office}{hours}</font>
+            <font face="arial" size="2">$$settings{office}{hours}</font>
           </td>
         </tr>
         |;
@@ -1780,7 +1781,7 @@ sub process_db {
     }
 }
 
-# ---------------------------------------------------------------- Add Posting to Bulletin Board
+# ---------------------------------------------------------------- Add Posting to Discussion Board
 sub addposting {
     my ($symb,$contrib,$cdom,$crs)=@_;
     my $status='';
@@ -3217,10 +3218,11 @@ sub process_assessment {
         ($cdom,$cnum) = split/_/,$cid;
     }
     my $destresdir = $destdir;
+    my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
     if ($context eq 'CSTR') {
-        $destresdir =~ s|/home/$uname/public_html/|/res/$udom/$uname/|;
+        $destresdir =~ s{^\Q$londocroot/priv/\E}{/res/};
     } elsif ($context eq 'DOCS') {
-        $destresdir =~ s|^/home/httpd/html/userfiles|/uploaded|;
+        $destresdir =~ s{^\Q$londocroot/userfiles\E}{/uploaded};
     }
     if ($cms eq 'bb5') {
         &parse_bb5_assessment($res,$docroot,$container,$settings,\%allanswers,\%allchoices,\@allids);
@@ -3367,8 +3369,8 @@ sub build_problem_container {
         push @{$sequencesfiles},$mapname.'.sequence';
     } else {
         $$containerdir = $pagedir.'/'.$mapname.'.page';
-        if (!-e "$destdir/pages") {
-            mkdir("$destdir/pages",0770);
+        if (!-e "$pagedir") {
+            mkdir("$pagedir",0770);
         }
         open($fh,">$$containerdir");
         $$total{page} ++;
@@ -3462,6 +3464,7 @@ sub write_bb5_questions {
     my ($allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$allanswers,$allchoices,$total,$newdir,$cid,$cdom,$cnum,$docroot) = @_;
     my $qnum = 0;
     my $pathstart;
+    my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
     if ($context eq 'CSTR') {
         $pathstart = '../..';
     } else {
@@ -3481,7 +3484,7 @@ sub write_bb5_questions {
         $qnum ++;
         my $output;
         my $permcontainer = $containerdir;
-        $permcontainer =~ s#/home/httpd/html/userfiles#uploaded#;
+        $permcontainer =~ s{^\Q$londocroot/userfiles\E}{uploaded};
         my $symb = $cid.'.'.$permcontainer.'___'.$qnum.'___lib/templates/simpleproblem.problem.0.';
         my %resourcedata = ();
         for (my $i=0; $i<10; $i++) {
@@ -3838,6 +3841,7 @@ sub write_bb5_questions {
 
 sub write_webct4_questions {
     my ($cms,$alldbquestids,$context,$settings,$dirname,$allanswers,$allchoices,$total,$cid,$cdom,$cnum,$destdir,$catinfo,$dirtitle) = @_;
+    my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
     my $qnum = 0;
     foreach my $id (@{$alldbquestids}) {
         $qnum ++;
@@ -3870,7 +3874,7 @@ sub write_webct4_questions {
                 }
             }
         }
-        $permcontainer =~ s#/home/httpd/html/userfiles#uploaded#;
+        $permcontainer =~ s{\Q$londocroot/userfiles\E}{uploaded};
         my $symb = $cid.'.'.$permcontainer.'___'.$qnum.'___lib/templates/simpleproblem.problem.0.';
         my %resourcedata = ();
         for (my $i=0; $i<10; $i++) {
@@ -4477,6 +4481,7 @@ sub test_for_html {
 
 sub write_bb6_questions {
     my ($allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$total,$newdir,$cid,$cdom,$cnum,$docroot) = @_;
+    my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
     my $qnum = 0;
     foreach my $id (@{$allids}) {
         my $questiontext = $$settings{$id}{question}{text};
@@ -4485,7 +4490,7 @@ sub write_bb6_questions {
         $qnum ++;
         my $output;
         my $permcontainer = $containerdir;
-        $permcontainer =~ s#/home/httpd/html/userfiles#uploaded#;
+        $permcontainer =~ s{\Q$londocroot/userfiles\E}{uploaded};
         my $symb = $cid.'.'.$permcontainer.'___'.$qnum.'___lib/templates/simpleproblem.problem.0.';
         my %resourcedata = ();
         for (my $i=0; $i<10; $i++) {
@@ -4979,10 +4984,11 @@ sub process_content {
     my ($cms,$res,$context,$docroot,$destdir,$settings,$dom,$user,$resrcfiles,$packages,$hrefs) = @_;
     my $xmlfile = $docroot.'/'.$res.".dat";
     my $destresdir = $destdir;
+    my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
     if ($context eq 'CSTR') {
-        $destresdir =~ s|/home/$user/public_html/|/res/$dom/$user/|;
+        $destresdir =~ s{^\Q$londocroot/priv/\E}{/res/};
     } elsif ($context eq 'DOCS') {
-        $destresdir =~ s|^/home/httpd/html/userfiles|/uploaded|;
+        $destresdir =~ s{^\Q$londocroot/userfiles\E}{/uploaded};
     }
     my $filetag = '';
     if ($cms eq 'bb5') {