--- loncom/imspackages/imsimport.pm 2004/04/08 09:19:39 1.6 +++ loncom/imspackages/imsimport.pm 2006/04/10 22:30:20 1.20 @@ -1,10 +1,32 @@ +# 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::imsimport; use strict; use Apache::Constants qw(:common :http :methods); use Apache::loncacc; use Apache::loncommon(); -use Apache::Log(); use Apache::lonnet; use Apache::imsprocessor; use HTML::Parser; @@ -16,6 +38,20 @@ use File::Basename(); # ---------------------------------------------------------------- Jscript One sub jscript_one { my ($fullpath,$jsref) = @_; + + my %body_layout = ('rightmargin' => "0", + 'leftmargin' => "0", + 'marginwidth' => "0", + 'topmargin' => "0", + 'marginheight' => "0"); + my $start_page = + &Apache::loncommon::start_page('Create IMS import directory',undef, + {'only_body' => 1, + 'add_entries' => \%body_layout, + 'js_ready' => 1,}); + my $end_page = + &Apache::loncommon::end_page({'js_ready' => 1,}); + $$jsref = <<"END_OF_ONE"; function verify() { if ((document.forms.dataForm.newdir.value == '') || (!document.forms.dataForm.newdir.value)) { @@ -39,22 +75,22 @@ function createWin() { document.dataForm.newdir.value = ""; newWindow = window.open("","CreateDir","HEIGHT=400,WIDTH=750,scrollbars=yes") newWindow.document.open() - newWindow.document.write("Create IMS import directory\\n") - newWindow.document.write("\\n") - newWindow.document.write("[Author Header]\\n") + newWindow.document.write('$start_page') + newWindow.document.write("\\n[Author Header]\\n") newWindow.document.write("\\n") newWindow.document.write("\\n") newWindow.document.write("\\n") newWindow.document.write("\\n") newWindow.document.write("\\n") - newWindow.document.write("
  

Location: $fullpath

New Directory

  
\\n") newWindow.document.write("Enter the name of the new directory where you will store the contents of your IMS package.

") - newWindow.document.write("") - newWindow.document.write("") - newWindow.document.write("") - newWindow.document.write("$fullpath") + newWindow.document.write("") + newWindow.document.write("") + newWindow.document.write("") + newWindow.document.write("$fullpath") newWindow.document.write("") newWindow.document.write("
") + newWindow.document.write("") + newWindow.document.write('$end_page') newWindow.document.close() newWindow.focus() } @@ -269,9 +305,12 @@ sub display_one { Please choose the CMS used to create your IMS content package.   @@ -294,7 +333,7 @@ Please choose the CMS used to create you   -Please choose a destination LON-CAPA directory in which to store the contents of the IMS package file. +Please choose a destination LON-CAPA directory in which to store the contents of the IMS package file. @@ -306,9 +345,9 @@ Please choose a destination LON-CAPA dir - - - + + + @@ -319,10 +358,10 @@ Please choose a destination LON-CAPA dir
- + - +
@@ -340,8 +379,8 @@ END_OF_ONE sub display_two { my ($r,$zipupload,$areas,$areaname,$cmsmap,$uname,$newdir,$numcrs,$fullpath) = @_; &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']); - my $cms = $ENV{'form.source'}; - my $dirname = $ENV{'form.newdir'}; + my $cms = $env{'form.source'}; + my $dirname = $env{'form.newdir'}; my $tempdir = &Apache::imsprocessor::create_tempdir('CSTR',$dirname,''); my $fname = &Apache::imsprocessor::uploadzip('CSTR',$tempdir,$zipupload); my $unzip_result = ''; @@ -350,6 +389,8 @@ sub display_two { $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname); } my %resources = (); + my %includedres = (); + my %includeditems = (); my %items = (); my %hrefs = (); my %resinfo = (); @@ -373,10 +414,13 @@ sub display_two { 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') { + if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4' + || $cms eq 'webctvista4') { foreach my $area (keys %{$$cmsmap{$cms}}) { if ($resources{$res}{type} eq $$cmsmap{$cms}{$area}) { $count{$area} ++; @@ -455,13 +499,13 @@ ENDBLOCK if ($area eq 'board') { $r->print("    "); } elsif ($area eq 'users') { $r->print("    "); @@ -508,7 +552,7 @@ ENDBLOCKTWO

Choose course:   @@ -530,7 +574,7 @@ Choose course:     - + @@ -552,10 +596,10 @@ ENDBLOCK
- + - +
@@ -579,29 +623,24 @@ sub display_three { my ($r,$uname,$udom,$areas,$areaname,$cmsmap,$destdir,$newdir) = @_; my $crs = ''; my $cdom = ''; - my $chome = ''; my $db_handling = ''; my $timenow = time; my $announce_handling = 'ok'; - my $cms = $ENV{'form.source'}; - if ( defined($ENV{'form.bb_crs'}) ) { - ($cdom,$crs) = split/\//,$ENV{'form.bb_crs'}; - $chome = &Apache::lonnet::homeserver($crs,$cdom); + my $cms = $env{'form.source'}; + if ( defined($env{'form.bb_crs'}) ) { + ($cdom,$crs) = split/\//,$env{'form.bb_crs'}; } - 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'}; + if ( defined($env{'form.user_crs'}) ) { + ($user_cdom,$user_crs) = split/\//,$env{'form.user_crs'}; } my $seqstem = "/res/$udom/$uname/$newdir"; - my %imports = (); + my %importareas = (); + my %includedres = (); + my %includeditems = (); + my %randompicks = (); my @targets = (); my %resources = (); my %items = (); @@ -620,55 +659,88 @@ sub display_three { my @pages = (); my @sequences = (); my @resrcfiles = (); + my @assessmentfiles = (); - my $tempdir = $ENV{'form.tempdir'}; + 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'}; + $db_handling = $env{'form.db_handling'}; } elsif ($area eq 'users') { - $user_handling = $ENV{'form.user_handling'}; + $user_handling = $env{'form.user_handling'}; + } + } + } + + 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; + if ($resources{$res}{type} eq 'webct.manifest' || + $resources{$res}{type} eq 'webct.assessment' || + $resources{$res}{type} eq 'webct.question') { + push(@assessmentfiles,$res); + } } } + 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); } - my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo); + + $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); - my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$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,'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,\%randompicks); - &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); + my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas,\@assessmentfiles); - &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); + &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,\%randompicks); - $r->print("

Step 3: Publish your new LON-CAPA materials

"); + $r->print("

IMS import completed

"); if ($cms eq 'bb5') { $r->print("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.

\n"); } elsif ($cms eq 'angel') { $r->print("Your IMS package has been processed successfully. A total of $total{seq} sequences, $total{page} pages, and $total{board} bulletin boards have been created.

\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' which includes 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.

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.

Display new directory
"); + if ($destdir =~ m-^/home/$uname/public_html/-) { + system (" rm -r -f $destdir/temp"); + } } elsif ($manifest_result eq 'nomanifest') { - $r->print("Processing of your IMS package failed, because the IMS content package did not contain an IMS manifest file ."); + $r->print("Processing of your IMS package failed, because the IMS content package did not contain an IMS manifest file."); } } @@ -754,40 +826,39 @@ sub handler { my $javascript = ''; my $page_name = ''; my $current_page = ''; - my $loadentries = ''; my $qcount = ''; # get personal information for this user - my $user=$ENV{'user.name'}; - my $dom=$ENV{'user.domain'}; + my $user=$env{'user.name'}; + my $dom=$env{'user.domain'}; # # re-attach user # - if ($ENV{'form.uploaduname'}) { - $ENV{'form.filename'}='/priv/'.$ENV{'form.uploaduname'}.'/'. - $ENV{'form.filename'}; + if ($env{'form.uploaduname'}) { + $env{'form.filename'}='/priv/'.$env{'form.uploaduname'}.'/'. + $env{'form.filename'}; } ($uname,$udom)= - &Apache::loncacc::constructaccess($ENV{'form.filename'}, + &Apache::loncacc::constructaccess($env{'form.filename'}, $r->dir_config('lonDefDomain')); unless (($uname) && ($udom)) { $r->log_reason($uname.' at '.$udom. - ' trying to publish file '.$ENV{'form.filename'}. + ' trying to publish file '.$env{'form.filename'}. ' - not authorized', $r->filename); return HTTP_NOT_ACCEPTABLE; } my $fn; - if ($ENV{'form.filename'}) { - $fn=$ENV{'form.filename'}; + if ($env{'form.filename'}) { + $fn=$env{'form.filename'}; $fn=~s/^http\:\/\/[^\/]+\///; $fn=~s/^\///; $fn=~s/(\~|priv\/)(\w+)//; $fn=~s/\/+/\//g; } else { - $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}. + $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}. ' unspecified filename for upload', $r->filename); return HTTP_NOT_FOUND; } @@ -797,7 +868,6 @@ sub handler { unless ($pathname eq '/') { $fullpath .= '/'; } - my $loadentries = ''; my @areas = (); my %cmsmap = (); @@ -809,41 +879,42 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - if ($ENV{'form.phase'} eq 'two') { + if ($env{'form.phase'} eq 'two') { &jscript_one($fullpath,\$javascript,$uname,$udom); - } elsif ($ENV{'form.phase'} eq 'three') { + } elsif ($env{'form.phase'} eq 'three') { &jscript_two(\$javascript,$user,$dom,\$numcrs); - } elsif ($ENV{'form.phase'} eq 'four') { + } elsif ($env{'form.phase'} eq 'four') { &jscript_three(\$javascript); } - $r->print("LON-CAPA Construction Space\n"); - - $r->print(&Apache::loncommon::bodytag('Upload IMS package to Construction Space',undef,$loadentries)); - - if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) { + $javascript = "\n"; + + my $title = 'Upload IMS package to Construction Space'; + $r->print(&Apache::loncommon::start_page($title, $javascript)); + + if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { $r->print('

'.&mt('Co-Author').': '.$uname. &mt(' at ').$udom.'

'); } - if ($ENV{'form.phase'} eq 'two') { + if ($env{'form.phase'} eq 'two') { my $flag = &Apache::lonupload::phasetwo($r,$fn,$uname,$udom,'imsimport'); if ($flag eq 'ok') { &display_one($r,$uname,$fn,$fullpath); } - } elsif ( ($ENV{'form.phase'} eq 'three') || ($ENV{'form.phase'} eq 'four') ) { - my $docroot = $ENV{'form.newdir'}; + } elsif ( ($env{'form.phase'} eq 'three') || ($env{'form.phase'} eq 'four') ) { + my $docroot = $env{'form.newdir'}; my $newdir = ''; if ($docroot =~ m|public_html/(.+)$|) { $newdir = $1; } - if ($ENV{'form.phase'} eq 'three') { + if ($env{'form.phase'} eq 'three') { &display_two ($r,$zipupload,\@areas,\%areaname,\%cmsmap,$uname,$newdir,\$numcrs,$fullpath); - } elsif ($ENV{'form.phase'} eq 'four') { + } elsif ($env{'form.phase'} eq 'four') { &display_three ($r,$uname,$udom,\@areas,\%areaname,\%cmsmap,$docroot,$newdir); } } else { &Apache::lonupload::phaseone($r,$fn,$uname,$udom,'imsimport'); } - $r->print(''); + $r->print(&Apache::loncommon::end_page()); return OK; } 1;