[LON-CAPA-cvs] cvs: modules /raeburn imsimportdocs.pm imsprocessor.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Tue, 02 Mar 2004 15:45:06 -0000


This is a MIME encoded message

--raeburn1078242306
Content-Type: text/plain

raeburn		Tue Mar  2 10:45:06 2004 EDT

  Added files:                 
    /modules/raeburn	imsprocessor.pm imsimportdocs.pm 
  Log:
  Modularization of imsimport.pm -> imsprocessor.pm
  imsprocessor.pm contains routines to allow import of IMS packages into both
  an author's contrsuction space, and also into a course directly via the DOCS interface.
  
  imsimportdocs provides the user interface for import on an IMS package directly into a course using the DOCS screen. Both are currently incomplete, as additional existing routines in imsimport.pm need to be modularized, (and ins ome cases modified) to support both DOCS and CSTR targets, before routines are moved to imsprocessor.pm
  
  
--raeburn1078242306
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20040302104506.txt"


Index: modules/raeburn/imsprocessor.pm
+++ modules/raeburn/imsprocessor.pm
package Apache::imsprocessor;

use Apache::lonnet;
use LONCAPA::Configuration;
 
sub create_tempdir {
    my ($caller,$pathinfo) = @_;   
    my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
    my $tempdir;
    if ($caller eq 'DOCS') {
        $tempdir =  $$configvars{'lonDaemons'}.'/tmp/'.$pathinfo;
        if (!-e "$tempdir") {
            mkdir("$tempdir",0755);
        }
    } elsif ($caller eq "CSTR") {
        if (!-e "$pathinfo/temp") {
            mkdir("$pathinfo/temp",0755);
        }
        $tempdir =  $pathinfo.'/temp';
    }
    return $tempdir;
}


sub expand_zip {
    my ($tempdir,$filename) = @_;
    my $zipfile = "$tempdir/$filename";
    if ($filename =~ m|\.zip$|i) {
        open(OUTPUT, "unzip -o $zipfile -d $tempdir  2> /dev/null |");
        while (<OUTPUT>) {
            print "$_<br />";
        }
        close(OUTPUT);
    } else {
        return 'nozip';
    }
    if ($filename =~ m|\.zip$|i) {
        unlink($zipfile);
    }
    return 'ok';
}

sub process_manifest {
    my ($cms,$tempdir,$resources,$items,$hrefs) = @_;
    my %toc = (
              bb5 => 'tableofcontents',
              angel => 'organization',
              );

    my @state = ();
    my $itm = '';
    my $identifier = '';
    my @seq = "Top";
    my $lastitem;
    $$items{'Top'}{'contentscount'} = 0;

    unless (-e "$tempdir/imsmanifest.xml") {
        return 'nomanifest';
    } 

    my $xmlfile = $tempdir.'/imsmanifest.xml';
    my $p = HTML::Parser->new
    (
       xml_mode => 1,
       start_h =>
           [sub {
                my ($tagname, $attr) = @_;
                push @state, $tagname;
                my $num = @state - 3;
                my $start = $num;
                my $statestr = '';
                foreach (@state) {
                    $statestr .= "$_ ";
                }
                if ( ($state[0] eq "manifest") && ($state[1] eq "organizations") && ($state[2] eq $toc{$cms}) ) {
                    my $searchstr = "manifest organizations $toc{$cms}";
                    while ($num > 0) {
                        $searchstr .= " item";
                        $num --; 
                    }
                    if (("@state" eq $searchstr) && (@state > 3)) {
                        $itm = $attr->{identifier};              
                        %{$$items{$itm}} = ();
                        $$items{$itm}{contentscount} = 0;
                        if ($cms eq 'bb5') {
                            $$items{$itm}{resnum} = $attr->{identifierref};
                            $$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]}} = ();
                                }
                                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;
                        }
                        my $path;
                        if (@seq > 1) {
                            $path = join(',',@seq);
                        } elsif (@seq > 0) {
                            $path = $seq[0];
                        }
                        $$items{$itm}{filepath} = $path;
                        $$items{$seq[-1]}{contentscount} ++;
                        $lastitem = $itm;
                    }
                } elsif ("@state" eq "manifest resources resource" ) {
                    $identifier = $attr->{identifier};
                    if ($cms eq 'bb5') {                 
                        $$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}} = ();
                } elsif ("@state" eq "manifest resources resource file") {
                    if ($cms eq 'bb5') {
                        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;
                        } 
                    }
                }
           }, "tagname, attr"],
        text_h =>
            [sub {
                my ($text) = @_;
              }, "dtext"],
        end_h =>
              [sub {
                  my ($tagname) = @_;
                  pop @state;
               }, "tagname"],
    );
    $p->parse_file($xmlfile);
    $p->eof;

    foreach my $itm (keys %contents) {
        @{$$items{$itm}{contents}} = @{$contents{$itm}};
    }
    return 'ok' ;
}

sub target_resources {
    my ($resources,$oktypes,$targets) = @_; 
    foreach my $key (keys %{$resources}) {
        if ( defined($$oktypes{$$resources{$key}{type}}) ) {
            push @{$targets}, $key;
        }
    }
    return;
}


sub copy_resources {
    my ($context,$cms,$hrefs,$tempdir,$targets,$url,$crs,$cdom,$chome,$destdir) = @_;
    if ($context eq 'DOCS') {
        my $path= $cdom.'/'.$crs.'/';
        my $filepath= $Apache::lonnet::perlvar{'lonDocRoot'};
        my @parts=split(/\//,$filepath.'/userfiles/'.$path);
        for (my $count=4; $count<@parts; $count++) {
            $filepath.="/$parts[$count]";
            if ((-e $filepath)!=1) {
	        mkdir($filepath,0777);
            }
        }
        foreach my $key (sort keys %{$hrefs}) {
            if (grep/^$key$/,@{$targets}) {
                %{$url{$key}} = ();
                foreach my $file (@{$$hrefs{$key}}) {
                    if ($cms eq 'bb5') {
                        my $filename = $file;
                        $filename =~ s/\//_/g;
                        $filename = 'ims_'.$key.'_'.$filename;
                        my $destination = $filepath.'/'.$filename;
                        if (-e "$destination") {
                            print STDERR "Can not copy file to $destination, as $filename already exists\n";
                        } else {
                            system("cp $tempdir/$key/$file $filepath/$filename");
                            my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$cdom.'/'.$crs.'/'.$filename,$chome);

                            if ($fetchresult eq 'ok') {
                                $$url{$key}{$filename} = '/uploaded/'.$path.$fname;
                            } else {
                                &Apache::lonnet::logthis('Failed to transfer '.$cdom.'/'.$crs.'/'.$filename.' to host '.$chome.': '.$fetchresult);
                                $$url{$key}{$filename} = '/adm/notfound.html';
                            }    
                        }
                    } elsif ($cms eq 'angel') {
                        $file =~ s-\\-/-g;
                        my $filename = $file;
                        $filename =~ s/\//_/g;
                        unless ($file eq 'pg'.$key.'.htm') {
                            $filename = 'ims_'.$key.'_'.$filename;
                            my $destination = $filepath.'/'.$filename;
                            if (-e "$destination") {
                                print STDERR "Can not copy file to $destination, as $filename already exists\n";
                            } else {
                                system("cp $tempdir/_assoc/$key/$file $filepath/$filename");
                                my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$cdom.'/'.$crs.'/'.$file,$chome);
                                if ($fetchresult eq 'ok') {
                                    $$url{$key}{$filename} = '/uploaded/'.$path.$fname;
                                } else {
                                    &Apache::lonnet::logthis('Failed to transfer '.$cdom.'/'.$crs.'/'.$filename.' to host '.$chome.': '.$fetchresult);
                                    $$url{$key}{$filename} = '/adm/notfound.html';
                                }
                            }
                        }
                    }
                }
            }
        }
    } elsif ($context eq 'CSTR') {
        if (!-e "$destdir/resfiles") {
            mkdir("$destdir/resfiles",0755);
        }
        if ($cms eq 'angel') { 
            foreach my $key (sort keys %href) {
                foreach my $file (@{$href{$key}}) {
                    $file =~ s-\\-/-g;
                    unless ($file eq 'pg'.$key.'.htm') {
                        if (!-e "$destdir/resfiles/$key") {
                            mkdir("$destdir/resfiles/$key",0755);
                        }
                    }
                    my $filepath = $file;
                    while ($filepath =~ m-(\w+)/(.+)-) {
                        $filepath = $2;
                        if (!-e "$destdir/resfiles/$key/$1") {
                            mkdir("$destdir/resfiles/$key/$1",0755);
                        }
                    }
                    unless ($file eq 'pg'.$key.'.htm') {
                        system("cp $tempdir/_assoc/$key/$file $destdir/resfiles/$key/$file");
                    }
                }
            }
        } elsif ($cms eq 'bb5') {
            foreach my $key (sort keys %href) {
                foreach my $file (@{$href{$key}}) {
                    my $filepath = $file;
                    if (!-e "$destdir/resfiles/$key") {
                        mkdir("$destdir/resfiles/$key",0755);
                    }
                    while ($filepath =~ m-(\w+)/(.+)-) {
                        $filepath = $2;
                        if (!-e "$destdir/resfiles/$key/$1") {
                            mkdir("$destdir/resfiles/$key/$1",0755);
                        }
                    }
                    system("cp $tempdir/$key/$file $destdir/resfiles/$key/$file");
                }
            }
        }
    }
}

1;
__END__
   


Index: modules/raeburn/imsimportdocs.pm
+++ modules/raeburn/imsimportdocs.pm
package Apache::imsimportdocs;

use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
use Apache::imsprocessor;
use LONCAPA::Configuration;

sub jscript_one {
    my $javascript = shift;
    $$javascript = qq#
function verify() {
 if ((document.forms.pickcms.uploadname.value == '')  || (!document.forms.pickcms.uploadname.value)) {
   alert("You must provide the name of the IMS package to be imported")
   return false
 }
 if (document.forms.pickcms.source.selectedIndex == 0) {
   alert("You must choose the Course Management System from which the IMS package was exported");
   return false
 }
 return true
}

function nextPage() {
 if (verify()) {
   document.forms.pickcms.submit()
 }
}
#;
 
}

sub jscript_two {
    my $javascript = shift;
    $$javascript = qq#
function setOptions(caller,itemnum) {
  var opForm = document.forms.pickoptions
  var menu = 1 + itemnum*2
  opForm.elements[menu].length = 0
  if (opForm.elements[itemnum*2].checked == true) {
    if (caller == "board") {
      opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
      opForm.elements[menu].options[1] = new Option("Import topics only","topics",true,true)
      opForm.elements[menu].options[2] = new Option("Import topics &amp; posts (with author)","allpost",true,true)
      opForm.elements[menu].options[3] = new Option("Import topics &amp; posts (no author)","allanon",true,true)
    }
    else { 
      if (caller == "users") {
        opForm.elements[menu].length = 0
        opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
        opForm.elements[menu].options[1] = new Option("Enroll students only","students",true,true)
        opForm.elements[menu].options[2] = new Option("Enroll all users","all",true,true)
      }
    }
  }
  else {
    opForm.elements[menu].options[0] = new Option("Not required","0",true,true)
  }
  opForm.elements[menu].selectedIndex = 0
}

function verify(caller) { 
  var opForm = document.forms.pickoptions
  var totcheck = 0;
  for (var i=0; i<caller; i++) {
    if (opForm.elements[2*i].checked == true) {
      totcheck ++
      if (opForm.elements[2*i].name == "board") { 
        if (opForm.elements[2*i+1].selectedIndex == 0) {     
          alert("You must select one of the additional options when importing Discussion Boards ")
          return false
        }
      }
      if (opForm.elements[2*i].name == "users") {
        if (opForm.elements[2*i+1].selectedIndex == 0) {     
          alert("You must select one of the additional options when importing Enrollment")
          return false
        }
      }
    }
  }
  if (totcheck == 0) {
    alert("You must check the Checkbox for at least one Content Type");
    return false
  }
  return true
}

function nextPage(caller) {
 if (verify(caller)) {
   document.forms.pickoptions.submit()
 }
}
#;
}

sub handler {
    my $r = shift;
    my $javascript = '';
    &Apache::loncommon::content_type($r,'text/html');
    $r->send_http_header;
    return OK if $r->header_only;

    my @areas = ("doc","extlink","announce","staff","board","quiz","survey","pool","users");
    my %cmsmap = ();
    %{$cmsmap{bb5}} = (
                announce => 'resource/x-bb-announcement',
                board => 'resource/x-bb-discussionboard',
                doc => 'resource/x-bb-document',
                extlink => 'resource/x-bb-externallink',
                pool => 'assessment/x-bb-pool',
                quiz => 'assessment/x-bb-quiz',
                staff => 'resource/x-bb-staffinfo',
                survey => 'assessment/x-bb-survey',
                users => 'course/x-bb-user',
                );
 
    %{$cmsmap{angel}} =  (
                board => 'BOARD',
                extlink => 'LINK',
                msg => 'MESSAGE',
                quiz => 'QUIZ',
                survey => 'FORM',
                );

    @{$cmsmap{angel}{doc}} = ('FILE','PAGE');

# get course data
    my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
    my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
    my $coursehome=$ENV{'course.'.$ENV{'request.course.id'}.'.home'};

# get personal data
 
    my $uname=$ENV{'user.name'};
    my $udom=$ENV{'user.domain'};
    my $plainname=&Apache::lonnet::escape(
                     &Apache::loncommon::plainname($uname,$udom));

# does this user have privileges to post, etc?
    my $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
    unless ($allowed) {
        $r->print("<html><head><title>The LearningOnline Network with CAPA</title></head>");
        $r->print(&Apache::loncommon::bodytag('Import IMS package'));  
        $r->print('<h3>'.&mt('Modification of Course Contents Disallowed').'</h3>'.&mt('Your current role does not grant you the right to modify course content in this course.').'</body></html>');
        return OK;
    }

    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
       ['phase']);

    if ($ENV{'form.phase'} eq 'one') {    
        &jscript_one(\$javascript);
    } elsif ($ENV{'form.phase'} eq 'two') {
        &jscript_two(\$javascript);
    }

# print screen
    $r->print(<<ENDHEAD);
<html>
<head>
<title>The LearningOnline Network with CAPA</title>
<script type="text/javascript">
<!--
$javascript
-->
</script>
</head>
ENDHEAD
# -------------------------------------------------------------------- Body tag
    $r->print(&Apache::loncommon::bodytag('Import IMS package'));
    if ($ENV{'form.phase'} eq 'one') {
        &display_one($r);       
    } elsif ($ENV{'form.phase'} eq 'two') {
        &display_two($r,$coursenum,\@areas,%cmsmap);
    } elsif ($ENV{'form.phase'} eq 'three') {
        &display_three($r,$coursenum,$coursedom,$coursehome,\@areas,%cmsmap);
    }   
    $r->print("</body><html>");
} 

sub uploadzip {
    my $tempdir = shift;
    my $fname=$ENV{'form.uploadname.filename'};
# Replace Windows backslashes by forward slashes
    $fname=~s/\\/\//g;
# Get rid of everything but the actual filename
    $fname=~s/^.*\/([^\/]+)$/$1/;
# Replace spaces by underscores
    $fname=~s/\s+/\_/g;
# Replace all other weird characters by nothing
    $fname=~s/[^\w\.\-]//g;
# See if there is anything left
    unless ($fname) { return 'error: no uploaded file'; }

# Save the file
    chomp($ENV{'form.uploadname'});
    open(my $fh,'>'.$tempdir.'/'.$fname);
    print $fh $ENV{'form.uploadname'};
    close($fh);
    return $fname;   
}

sub display_one {
    my $r = shift;
    my $timestamp = time;
    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']);

    $r->print(<<ENDBLOCK);
<form action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" name="pickcms">
  <table border='0' bgcolor='#F6F6F6' cellspacing='0' cellpadding ='0' width='100%'>
   <tr>
    <td colspan='2'>
     <table border='0' cellspacing='0' cellpadding='0'>
      <tr>
        <td colspan='2'  align='left'>&nbsp;
        </td>
       </tr>
       <tr bgcolor='#CCCCFF'>
        <td valign='middle'><img src='/res/adm/pages/bl_step1.gif'>&nbsp;
        </td>
        <td width='100%' align='left'>&nbsp;&nbsp;
         <font face='arial,helvetica,sans-serif'><b>Specify the Course Management system used to create the package.</b>&nbsp;&nbsp;
         </font>
       </td>
      </tr>
      <tr>
       <td colspan='2'>&nbsp;</td>
      </tr>
      <tr>
       <td>&nbsp;</td>
       <td>
        <font face='Arial,Helvetica,sans-serif'>
Please choose the CMS used to create your IMS content package.&nbsp;&nbsp;
        <select name="source">
         <option value='-1' selected="true">Please select
         <option value='bb5'>Blackboard 5
         <option value='angel'>ANGEL
        </select>
        </font>
       </td>
      </tr>
      <tr>
       <td colspan='2'>&nbsp;</td>
      </tr>
      <tr>
       <td colspan='2'>&nbsp;</td>
      </tr>
      <tr bgcolor='#CCCCFF'>
        <td valign='middle'><img src='/res/adm/pages/bl_step2.gif'>&nbsp;
        </td>
        <td width='100%' align='left'>&nbsp;&nbsp;
         <font face='arial,helvetica,sans-serif'><b>Locate the IMS content package you wish to upload.</b>&nbsp;&nbsp;
         </font>
       </td>
      </tr>
      <tr>
       <td colspan='2'>&nbsp;</td>
      </tr>
      <tr>
       <td colspan='2'>&nbsp;
        <input type="hidden" name="folder" value="$ENV{'form.folder'}" />
        <input type="hidden" name="phase" value="two" />
        <input type="file" name="uploadname" size="40" />
       </td>
      </tr>
      <tr>
       <td colspan='2'>&nbsp;</td>
      </tr>
      <tr>
       <td>&nbsp;</td>
       <td><font face='arial,helvetica,sans-serif'>If you have selected the CMS, and located the IMS package, you should click the 'Upload IMS package' button to upload the file to the server.</font></td>
      </tr>
      <tr>
       <td colspan='2'>&nbsp;</td>
      </tr>
      <tr
       <td colspan='2'>
        <table border='0' cellspacing='0' cellpadding='0' width="100%">
         <tr>
          <td align='left'>
           <input type="button" name="exitpage" value="Exit now" onClick="javascript:self.close()">
          </td>
          <td align='right'>
           <input type="button" name="nextpage" value="Upload IMS package" onClick="javascript:nextPage()">
          </td>
         </tr>
        </table>
       </td>
      </tr>
     </table>
    </td>
   </tr>
  </table>
</form>
ENDBLOCK
}


sub display_two {
    my ($r,$crs,$areasref,%cmsmap) = @_;
    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']);
    my $cms = $ENV{'form.source'};
    my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs);
    my $fname = &uploadzip($tempdir);
    my $unzip_result = '';
    my $manifest_result = '';
    unless ($tempdir eq '') {
        $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname);
    }
    my %resources = ();
    my %items = ();
    my %hrefs = ();
    my %count = ();
    my @bgcolors = ("#eeeeee","#dddddd");

    my $counter = 0;
    my $iter = 0;
    my %count = (
                announce => 0,
                board => 0,
                doc => 0,
                extlink => 0,
                msg => 0,
                pool => 0,
                quiz => 0,
                staff => 0,
                survey => 0,
                users => 0,
                );

    my %areaname = (
                announce => 'Announcements',
                board => 'Discussion Boards',
                doc => 'Documents, pages &amp; folders',
                extlink => 'Links to external sites',
                pool => 'Question pools',
                quiz => 'Quizzes',
                staff => 'Staff information',
                survey => 'Surveys',
                users => 'Enrollment',
                );
         
    if ($unzip_result eq 'ok') {
        $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs);
        if ($manifest_result eq 'ok') {
            foreach my $res (sort keys %resources) {
                if ($cms eq 'bb5') {
                    foreach my $area (keys %{$cmsmap{$cms}}) {
                        if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
                            $count{$area} ++;
                        }
                    }
                } elsif ($cms eq 'angel') {
                    foreach my $area (keys %{$cmsmap{$cms}}) {
                        if ($area eq 'doc') {
                            if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) {
                                $count{$area} ++;
                            }
                        } elsif ($resources{$res}{type} eq $cmsmap{$cms}{$area}) {
                            $count{$area} ++;
                        }
                    }
                }
            }
            $r->print(<<ENDBLOCK);
<form name="pickoptions" method="post">
  <table border='0' bgcolor='#F6F6F6'' cellspacing='0' cellpadding ='0' width='100%'>
   <tr>
    <td colspan='2'>
     <table border='0' cellspacing='0' cellpadding='0'>
      <tr>
       <td colspan='2'  align='left'>&nbsp;
       </td>
      </tr>
      <tr bgcolor='#CCCCFF'>
       <td valign='middle'><img src='/res/adm/pages/bl_step3.gif'>
       </td>
       <td width='100%' align='left'>&nbsp;&nbsp;
        <font face='arial,helvetica,sans-serif'><b>Choose which content types you wish to import</b></font>
       </td>
      </tr>
      <tr>
       <td colspan='2'>&nbsp;</td>
      </tr>
      <tr>
       <td>&nbsp;</td>
       <td>
        <table border='0' cellspacing='0' cellpadding='1' bgcolor='#000000'>
         <tr>
          <td>
           <table border='0' cellspacing='0' cellpadding='0' bgcolor='#ffffff' width='100%'>
            <tr>
             <td>
              <table border='0' cellspacing='1' cellpadding='1' bgcolor='#ffffff' width='100%'>
               <tr bgcolor='#CCCCFF'>
                <td align='center'><font face='arial,helvetica,sans-serif'><b>Import?</b></font></td>           
                <td align='center'><font face='arial,helvetica,sans-serif'><b>Content type</b></font></td>
                <td align='center'><font face='arial,helvetica,sans-serif'><b>Additional options</b></font></td>
               </tr>
ENDBLOCK
            foreach my $area (@{$areasref}) {
                if ($count{$area} > 0) {
                    my $count_tag = 'flag_'.$counter;
                    $r->print("               <tr bgcolor='@bgcolors[$iter]'>
                <td align='left'><font face='arial,helvetica,sans-serif'><input name='$area' type='checkbox' ");
                    if ($area eq 'board' || $area eq 'users') {
                        $r->print(qq|onClick='javascript:setOptions("$area","$counter")'|);
                    }
                    $r->print("/></font></td>
                <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;$areaname{$area}&nbsp;&nbsp; - $count{$area} item(s)</font></td>");
                    if ($area eq 'board') {
                        $r->print("            <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;
                 <select name='bb_handling'>
                  <option value='-2'>&lt;-- Check Import first
                 </select></font>
                </td>");
                    } elsif ($area eq 'users') {
                        $r->print("            <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;
                 <select name='user_handling'>
                  <option value='-2'>&lt;-- Check Import first
                 </select>
                 </font>        
                </td>");
                    } else {
                        $r->print("            <td align='left'><font face='arial,helvetica,sans-serif'>&nbsp;&nbsp;None<input type='hidden' name='$count_tag' /></font></td>");
                    }
                    $counter ++;
                    $iter = $counter%2;
                }
            }
            $r->print(<<ENDDOCUMENT);
               </tr>
              </table>
             </td>
            </tr>
           </table>
          </td>
         </tr>
        </table>
       </td>
      </tr>
      <tr>
       <td colspan='2'>&nbsp;<br /><br /></td>
      </tr>
      <tr>
       <td>&nbsp;</td>
       <td><font face='arial,helvetica,sans-serif'>Once you have checked the checkboxes for all areas you wish to import from the IMS package, and selected options (if available) you should click the 'Complete Import' button.</font></td>
      </tr>
      <tr>
       <td colspan='2'>&nbsp;
          <input type="hidden" name="folder" value="$ENV{'form.folder'}" />
          <input type="hidden" name="source" value="$cms" />
          <input type="hidden" name="tempdir" value="$tempdir" />
          <input type="hidden" name="phase" value="three" />
       </td>
      </tr>
      <tr>
       <td colspan='2'>
        <table border='0' cellspacing='0' cellpadding='0' width="100%">
         <tr>
          <td align='left'>
           <input type='button' name='exitpage' value='Exit now' onClick="javascript:self.close()">
          </td>
          <td align='right'>
           <input type="button" name="nextpage" value="Complete Import" onClick="javascript:nextPage($counter)">
          </td>
         </tr>
        </table>
       </td>
      </tr>
     </table>
    </td>
   </tr>
  </table>
ENDDOCUMENT
        } else {
            $r->print("Unpacking of your IMS package failed because an IMS manifest file was not located in the package\n");
        }
    } else {
        $r->print("Processing of your IMS package failed because the file you uploaded could not be unzipped\n");
    }
}


sub display_three {
   my ($r,$crs,$cdom,$chome,$areas,%cmsmap) = @_;
   $r->print("You reached phase three");
   my $cms = $ENV{'form.source'};
   my $tempdir = $ENV{'form.tempdir'};
   my $longcrs = '';
   if ($crs =~ m/^(\d)(\d)(\d)/) {
       $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
   }
   my $destdir = '';
   my %imports = ();
   my @targets = ();
   my %resources = ();
   my %items = ();
   my %hrefs = ();
   my %urls = ();
   foreach my $area (@{$areas}) {
       if (defined($ENV{"form.$area"}) ) {          
           if ($cms eq 'angel' && $area eq 'doc') {
               foreach (@{$cmsmap{$cms}{$area}}) {
                   $imports{$_} = 1;
               }
           } else {
               $imports{$cmsmap{$cms}{$area}} = 1;
           }
       }
   }
   
   my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs);
   if ($manifest_result eq 'ok') {
       &Apache::imsprocessor::target_resources(\%resources,\%imports,\@targets);
       $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$chome,$destdir); 
   }
}

1;
__END__

--raeburn1078242306--