--- loncom/imspackages/imsimportdocs.pm 2004/03/09 16:34:34 1.2 +++ loncom/imspackages/imsimportdocs.pm 2013/12/30 21:46:52 1.33 @@ -1,3 +1,30 @@ +# The LearningOnline Network with CAPA +# +# $Id: imsimportdocs.pm,v 1.33 2013/12/30 21:46:52 raeburn Exp $ +# +# 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); @@ -6,58 +33,48 @@ use Apache::londocs; use Apache::loncommon; use Apache::lonlocal; use Apache::imsprocessor; -use LONCAPA::Configuration; +use LONCAPA::map(); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + use strict; 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# + my %lt = &Apache::lonlocal::texthash( + se => 'Select', + to => 'Import topics only', + tp => 'Import topics + posts (with author)', + tn => 'Import topics + posts (no author)', + es => 'Enroll students only', + ea => 'Enroll all users', + nr => 'Not required', + id => 'You must select one of the additional options when importing Discussion Boards.', + ie => 'You must select one of the additional options when importing Enrollment.', + ct => 'You must check at least one Content Type.', + ); + return <<"ENDJS"; 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 & posts (with author)","allpost",true,true) - opForm.elements[menu].options[3] = new Option("Import topics & posts (no author)","allanon",true,true) + opForm.elements[menu].options[0] = new Option("$lt{'se'}","-1",true,true) + opForm.elements[menu].options[1] = new Option("$lt{'to'}","topics",true,true) + opForm.elements[menu].options[2] = new Option("$lt{'tp'}","allpost",true,true) + opForm.elements[menu].options[3] = new Option("$lt{'tn'}","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) + opForm.elements[menu].options[0] = new Option("$lt{'se'}","-1",true,true) + opForm.elements[menu].options[1] = new Option("$lt{'es'}","students",true,true) + opForm.elements[menu].options[2] = new Option("$lt{'ea'}","all",true,true) } } } else { - opForm.elements[menu].options[0] = new Option("Not required","0",true,true) + opForm.elements[menu].options[0] = new Option("$lt{'nr'}","0",true,true) } opForm.elements[menu].selectedIndex = 0 } @@ -70,20 +87,20 @@ function verify(caller) { 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 ") + alert("$lt{'id'}") 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") + alert("$lt{'ie'}") return false } } } } if (totcheck == 0) { - alert("You must check the Checkbox for at least one Content Type"); + alert("$lt{'ct'}"); return false } return true @@ -94,245 +111,105 @@ function nextPage(caller) { document.forms.pickoptions.submit() } } -#; + +ENDJS + } -sub jscript_three { - my $javascript = shift; - $$javascript = qq| +sub jscript_two { + return <<"ENDJS"; function init(tf) { setTimeout("self.close()",3000) tf.submit(); } - |; + +ENDJS } 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 @areas = (); 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'); + my %areaname = (); + &Apache::imsprocessor::ims_config(\@areas,\%cmsmap,\%areaname); # 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'}; + my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'}; + my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'}; # get personal data - my $uname=$ENV{'user.name'}; - my $udom=$ENV{'user.domain'}; - my $plainname=&Apache::lonnet::escape( + my $uname=$env{'user.name'}; + my $udom=$env{'user.domain'}; + my $plainname=&escape( &Apache::loncommon::plainname($uname,$udom)); # does this user have privileges to post, etc? - my $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'}); + 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('

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

'.&mt('Your current role does not grant you the right to modify course content in this course.').''); + $r->print(&Apache::loncommon::start_page('Import IMS package',undef, + {'only_body' => 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.') + .'

' + .&Apache::loncommon::end_page() + ); 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); - } elsif ($ENV{'form.phase'} eq 'three') { - &jscript_three(\$javascript); + my $javascript; + if ($env{'form.phase'} eq 'one') { + $javascript = &jscript_one(); + } elsif ($env{'form.phase'} eq 'two') { + $javascript = &jscript_two(); } + $javascript = + "\n"; + my $headline = 'Import IMS package'; + my $start_page = &Apache::loncommon::start_page($headline, + $javascript, + {'only_body' => 1,}) + .'

'.&mt($headline).'

'; # print screen - $r->print(< - -The LearningOnline Network with CAPA - - -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,$uname,$udom,\@areas,%cmsmap); + $r->print($start_page); + + if ($env{'form.phase'} eq 'one') { + &display_one($r,$coursenum,\@areas,\%areaname,%cmsmap); + } elsif ($env{'form.phase'} eq 'two') { + &display_two($r,$coursenum,$coursedom,$uname,$udom,\@areas,%cmsmap); } - $r->print(""); + $r->print(&Apache::loncommon::end_page()); return OK; -} - -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) = @_; - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']); - - $r->print(< - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  -
  -    - Specify the Course Management system used to create the package.   - -
 
  - -Please choose the CMS used to create your IMS content package.   - - -
 
 
  -    - Locate the IMS content package you wish to upload.   - -
 
  - - - -
 
 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.
 
- - - - -
- - - -
-
- - - - -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 ($r,$crs,$areasref,$areaname,%cmsmap) = @_; + my $cms = $env{'form.source'}; my $timenow = time; my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs,$timenow); - my $fname = &uploadzip($tempdir); + my $fname = &Apache::imsprocessor::uploadzip('DOCS',$tempdir); my $unzip_result = ''; my $manifest_result = ''; unless ($tempdir eq '') { $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname); } my %resources = (); + my %includedres = (); + my %includeditems = (); my %items = (); my %hrefs = (); my %resinfo = (); my %count = (); - my @bgcolors = ("#eeeeee","#dddddd"); - my $counter = 0; - my $iter = 0; my %count = ( announce => 0, board => 0, @@ -346,196 +223,186 @@ sub display_two { users => 0, ); - my %areaname = ( - announce => 'Announcements', - board => 'Discussion Boards', - doc => 'Documents, pages & 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,\%resinfo); - 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} ++; - } - } + if ($unzip_result ne 'ok') { + $r->print( + &Apache::loncommon::confirmwrapper( + &Apache::lonhtmlcommon::confirm_success( + &mt('Processing of your IMS package failed because the file you' + .' uploaded could not be unzipped.'),1) + .'
'.&mt('Error: [_1]',$unzip_result)) + ); + return(); + } + + # Get manifest file from package + $manifest_result = &Apache::imsprocessor::process_manifest( + $cms,$tempdir,\%resources,\%items,\%hrefs, + \%resinfo,'choose',\%includedres,\%includeditems); + if ($manifest_result ne 'ok') { + $r->print( + '
'.&Apache::loncommon::confirmwrapper( + &Apache::lonhtmlcommon::confirm_success( + &mt('Unpacking of your IMS package failed because an IMS manifest file' + .' was not located in the package.'),1)) + ); + return(); + } + + # Count areas depending on cms version + foreach my $res (sort keys %resources) { + if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4') { + foreach my $area (keys %{$cmsmap{$cms}}) { + if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) { + $count{$area} ++; } } - $r->print(< - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  -
-    - Choose which content types you wish to import -
 
  - - - - -
- - - - -
- - - - - - -ENDBLOCK - foreach my $area (@{$areasref}) { - if ($count{$area} > 0) { - my $count_tag = 'flag_'.$counter; - $r->print(" - - "); - if ($area eq 'board') { - $r->print(" "); - } elsif ($area eq 'users') { - $r->print(" "); - } else { - $r->print(" "); - } - $counter ++; - $iter = $counter%2; + } elsif ($resources{$res}{type} eq $cmsmap{$cms}{$area}) { + $count{$area} ++; } } - $r->print(< -
Import?Content typeAdditional options
print(qq|onClick='javascript:setOptions("$area","$counter")'|); + } elsif ($cms eq 'angel5') { + foreach my $area (keys %{$cmsmap{$cms}}) { + if ($area eq 'doc') { + if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) { + $count{$area} ++; } - $r->print("/>  $areaname{$area}   - $count{$area} item(s)   - -    - - -   None
-
-
-
 

-    - Choose display options for listing of contents of top level of package. -
 
  - - - - - - - -
Display listing of contents in a new folder, with folder name:   
Append listing of contents of top level of package to contents list for the current folder.
-
 
 Once you have checked the checkboxes for all areas you wish to import from the IMS package, selected options (if available), and selected a display option for the package contents you should click the 'Complete Import' button.
  - - - - -
- - - - - -
- - - -
-
-
-ENDDOCUMENT + } else { # Unknown cms format + $r->print( + '' + .&mt('Unsupported IMS format: [_1]',$cms) + .'
' + ); + # return(); + } + } + + + # Start output: Step 1 and step 2 + + $r->print( + '
' + .&Apache::lonhtmlcommon::topic_bar( + 1,&mt('Choose which content types you wish to import')) + .'

' + .&mt('Check the checkboxes for all areas you wish to import from the IMS package:') + .'

' + ); + + $r->print( + &Apache::loncommon::start_data_table() + .&Apache::loncommon::start_data_table_header_row() + .''.&mt('Import?').'' + .''.&mt('Content type').'' + .''.&mt('Additional options').'' + .&Apache::loncommon::end_data_table_header_row() + ); + + # Display import row for each area/content type + foreach my $area (@{$areasref}) { + unless ($count{$area} > 0) { next }; + + my $count_tag = 'flag_'.$counter; + + # Checkbox: Import? + $r->print( + &Apache::loncommon::start_data_table_row() + .'print(qq| onclick='javascript:setOptions("$area","$counter")'|); + } + + $r->print(' />'); + + # Content Type + $r->print( + '' + .$$areaname{$area}.'   - ' + .&mt('[quant,_1,item]',$count{$area}) + .'' + ); + + # Additional Options + $r->print(''); + if ($area eq 'board') { + $r->print( + '' + ); + } elsif ($area eq 'users') { + $r->print( + '' + ); } else { - $r->print("Unpacking of your IMS package failed because an IMS manifest file was not located in the package\n"); + $r->print( + &mt('None') + .'' + ); } - } else { - $r->print("Processing of your IMS package failed because the file you uploaded could not be unzipped\n"); + $r->print(''); + + $r->print(&Apache::loncommon::end_data_table_row()); + $counter ++; } -} + $r->print(&Apache::loncommon::end_data_table()); -sub display_three { - my ($r,$crs,$cdom,$chome,$uname,$udom,$areas,%cmsmap) = @_; - my $folder = $ENV{'form.folder'}; - my $cms = $ENV{'form.source'}; - my $tempdir = $ENV{'form.tempdir'}; + $r->print( + &Apache::lonhtmlcommon::topic_bar( + 2,&mt('Choose display options for listing of contents of top level of package')) + .'

' + .&mt('Select a display option for the package content:') + .'

' + ); + $r->print( + '' + .' ' + .'
' + .'' + ); + + # Buttons + $r->print( + '' + .'' + .'' + .'' + ); + $r->print( + '
' + .'

' + .'' + .' ' + .'' + .'

' + ); + + $r->print('
'); +} + +sub display_two { + my ($r,$crs,$cdom,$uname,$udom,$areas,%cmsmap) = @_; + my $folder = $env{'form.folder'}; + my $cms = $env{'form.source'}; + my $tempdir = $env{'form.tempdir'}; my $longcrs = ''; 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 = (); @@ -557,7 +424,6 @@ sub display_three { my $timenow = time; my $destdir = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles/'.$cdom.'/'.$crs.'/'.$timenow; - my $dirname = $cdom.'/'.$crs.'/'.$timenow; my $seqstem = "/uploaded/$cdom/$crs/$timenow"; my $db_handling = ''; my $user_handling = ''; @@ -565,135 +431,149 @@ sub display_three { my $toplevel = ''; my $foldername = ''; my %topitems = (); - if (defined($ENV{'form.toplevel'}) ) { - $toplevel = $ENV{'form.toplevel'}; + if (defined($env{'form.toplevel'}) ) { + $toplevel = $env{'form.toplevel'}; } - if (defined($ENV{'form.foldername'}) ) { - $foldername = $ENV{'form.foldername'}; + if (defined($env{'form.foldername'}) ) { + $foldername = $env{'form.foldername'}; } - + foreach my $area (@{$areas}) { - if (defined($ENV{"form.$area"}) ) { - if ($cms eq 'angel' && $area eq 'doc') { + if (defined($env{"form.$area"}) && ($env{'form.'.$area} ne '')) { + if ($cms eq 'angel5' && $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); + + my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'prepare',\%includedres,\%includeditems); if ($manifest_result eq 'ok') { - &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); + 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') { + + my @path = ($cdom,$crs,$timenow); + my $fullpath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles'; + foreach my $item (@path) { + $fullpath .= '/'.$item; + if (!-e "$fullpath") { + mkdir("$fullpath",0770); + } + } + my @namedirs = ("resfiles","sequences","pages","problems"); + foreach my $name (@namedirs) { + if (!-e "$fullpath/$name") { + mkdir("$fullpath/$name",0770); + } + } + &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,$tempdir,$destdir,\%items,\%resources,\@boards,\@announcements,\@quizzes,\@surveys,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$dirname,$seqstem,\@resrcfiles); + &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,\%resources,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas); + + &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); - &Apache::imsprocessor::build_structure($cms,'DOCS',$destdir,\%resinfo,\%items,\%resources,\%hrefs,$udom,$uname,'',$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames); - foreach my $item (@pages) { - my $path = $timenow.'/pages/'; - ©_items($item,$path,$cdom,$chome,$crs); + my $filename = $timenow.'/pages/'.$item; + my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,''); } foreach my $item (@sequences) { unless ($item eq 'Top.sequence' && $toplevel eq 'oldfolder') { - my $path = $timenow.'/sequences/'; - ©_items($item,$path,$cdom,$chome,$crs); + my $filename = $timenow.'/sequences/'.$item; + my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,''); } } foreach my $item (@resrcfiles) { - my $path = $timenow.'/resfiles/'; - ©_items($item,$path,$cdom,$chome,$crs); + my $filename = $timenow.'/resfiles/'.$item; + my $fetchresult= &Apache::lonnet::process_coursefile('propagate',$crs,$cdom,$filename,''); } my @imports = (); if ($toplevel eq 'oldfolder') { for (my $i=0; $i<@topurls; $i++) { - my $url = &Apache::lonnet::unescape($topurls[$i]); - my $name = &Apache::lonnet::unescape($topnames[$i]); - push @imports, $name, $url; + my $url = &unescape($topurls[$i]); + my $name = &unescape($topnames[$i]); + push(@imports, [$name, $url]); } } elsif ($toplevel eq 'newfolder') { - my $url = &Apache::lonnet::unescape("/uploaded/$cdom/$crs/$timenow/sequences/Top.sequence"); - my $name = &Apache::lonnet::unescape("$ENV{'form.foldername'}"); - push @imports, $name, $url; + my $url = &unescape("/uploaded/$cdom/$crs/$timenow/sequences/Top.sequence"); + my $name = &unescape("$env{'form.foldername'}"); + push(@imports, [$name, $url]); } my $errtext=''; my $fatal=0; ($errtext,$fatal)= &Apache::londocs::mapread($crs,$cdom,$folder.'.sequence'); - if ($#Apache::lonratedt::order<1) { - $Apache::lonratedt::order[0]=1; - $Apache::lonratedt::resources[1]=''; + if ($#LONCAPA::map::order<1) { + $LONCAPA::map::order[0]=1; + $LONCAPA::map::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"; + &Apache::lonnet::logthis("Fatal error during group_import."); } } - $r->print(< - - - - - - - - - - - - - - - - - -
  -
-    - Your import is complete -
 
  -ENDBLOCK - my $initblock = qq| -
- - -

Changes will become active for your current session after - - |; - $initblock .= &mt('or the next time you log in.'); - $initblock .= qq|

|; - $r->print($initblock); - $r->print(< -
-ENDBLOCKTWO -} + if ($tempdir =~ m/^\/home\/httpd\/perl\/tmp\/$crs\/\d{10}/) { + system("rm -r -f $tempdir"); + } -sub copy_items { - my ($filename,$fpath,$cdom,$chome,$crs) = @_; - my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$cdom.'/'.$crs.'/'.$filename.':'.$fpath,$chome); + # All done, display success message + $r->print( + '

' + .&mt('Your import is complete.') + .'

' + ); + # Re-initialize Button + my $initbutton = + ''; + $r->print( + '
' + .'' + .'' + .'' + .'

' + .&mt('Changes will become active for your current session after [_1]' + .', or the next time you log in.' + ,$initbutton) + .'

' + .'
' + ); } 1;