--- loncom/imspackages/imsimportdocs.pm 2004/04/08 09:19:39 1.6 +++ loncom/imspackages/imsimportdocs.pm 2005/02/14 22:46:12 1.9 @@ -1,3 +1,26 @@ +# Copyright Michigan State University Board of Trustees +# +# This file is part of the LearningOnline Network with CAPA (LON-CAPA). +# +# LON-CAPA is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# LON-CAPA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LON-CAPA; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# /home/httpd/html/adm/gpl.txt +# +# http://www.lon-capa.org/ +# + package Apache::imsimportdocs; use Apache::Constants qw(:common :http :methods); @@ -135,7 +158,7 @@ sub handler { my $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'}); unless ($allowed) { $r->print("The LearningOnline Network with CAPA"); - $r->print(&Apache::loncommon::bodytag('Import IMS package')); + $r->print(&Apache::loncommon::bodytag('Import IMS package',undef,'',1)); $r->print('

'.&mt('Modification of Course Contents Disallowed').'

'.&mt('Your current role does not grant you the right to modify course content in this course.').''); return OK; } @@ -164,7 +187,7 @@ $javascript ENDHEAD # -------------------------------------------------------------------- Body tag - $r->print(&Apache::loncommon::bodytag('Import IMS package')); + $r->print(&Apache::loncommon::bodytag('Import IMS package',undef,'',1)); if ($ENV{'form.phase'} eq 'one') { &display_one($r); } elsif ($ENV{'form.phase'} eq 'two') { @@ -210,6 +233,7 @@ Please choose the CMS used to create you @@ -285,6 +309,8 @@ sub display_two { $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname); } my %resources = (); + my %includedres = (); + my %includeditems = (); my %items = (); my %hrefs = (); my %resinfo = (); @@ -307,10 +333,10 @@ sub display_two { ); 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') { + if ($cms eq 'bb5' || $cms eq 'bb6') { foreach my $area (keys %{$cmsmap{$cms}}) { if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) { $count{$area} ++; @@ -483,7 +509,9 @@ sub display_three { 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 = (); @@ -518,15 +546,15 @@ sub display_three { if (defined($ENV{'form.foldername'}) ) { $foldername = $ENV{'form.foldername'}; } - + foreach my $area (@{$areas}) { - if (defined($ENV{"form.$area"}) ) { + 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'}; @@ -535,9 +563,35 @@ sub display_three { } } } - - 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) { @@ -552,23 +606,26 @@ sub display_three { mkdir("$fullpath/$name",0770); } } - &Apache::imsprocessor::target_resources(\%resources,\%imports,\@targets); - my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$chome,$destdir,$timenow); + &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets); my @boards = (); my @announcements = (); my @quizzes = (); my @surveys = (); + my @pools = (); my @groups = (); my %messages = (); my @timestamp = (); my %boardnum = (); my @topurls = (); my @topnames = (); + my @packages = (); + + &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); - &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); + 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); + &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; @@ -604,7 +661,7 @@ sub display_three { $Apache::lonratedt::order[0]=1; $Apache::lonratedt::resources[1]=''; } - my ($errtext,$fatal)=&Apache::londocs::group_import($crs, $cdom, $folder,@imports); + my ($errtext,$fatal)=&Apache::londocs::group_import($crs,$cdom,$folder,'sequence','imsimport',@imports); if ($fatal) { print STDERR "Fatal error during group_import\n"; } @@ -644,7 +701,7 @@ ENDBLOCK |; - $initblock .= &mt('or the next time you log in.'); + $initblock .= ', '.&mt('or the next time you log in.'); $initblock .= qq||; $r->print($initblock); $r->print(<