--- loncom/imspackages/imsimportdocs.pm 2009/11/20 17:01:11 1.28 +++ loncom/imspackages/imsimportdocs.pm 2017/11/05 20:00:48 1.35 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: imsimportdocs.pm,v 1.28 2009/11/20 17:01:11 bisitz Exp $ +# $Id: imsimportdocs.pm,v 1.35 2017/11/05 20:00:48 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,7 +33,6 @@ 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; @@ -41,54 +40,41 @@ 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 } @@ -101,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 @@ -125,22 +111,23 @@ 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; @@ -177,15 +164,11 @@ sub handler { return OK; } - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['phase']); - - if ($env{'form.phase'} eq 'one') { - &jscript_one(\$javascript); + my $javascript; + if ($env{'form.phase'} eq 'one') { + $javascript = &jscript_one(); } elsif ($env{'form.phase'} eq 'two') { - &jscript_two(\$javascript); - } elsif ($env{'form.phase'} eq 'three') { - &jscript_three(\$javascript); + $javascript = &jscript_two(); } $javascript = @@ -200,59 +183,16 @@ sub handler { $r->print($start_page); if ($env{'form.phase'} eq 'one') { - &display_one($r); + &display_one($r,$coursenum,\@areas,\%areaname,%cmsmap); } elsif ($env{'form.phase'} eq 'two') { - &display_two($r,$coursenum,\@areas,\%areaname,%cmsmap); - } elsif ($env{'form.phase'} eq 'three') { - &display_three($r,$coursenum,$coursedom,$uname,$udom,\@areas,%cmsmap); + &display_two($r,$coursenum,$coursedom,$uname,$udom,\@areas,%cmsmap); } $r->print(&Apache::loncommon::end_page()); return OK; -} - - -sub display_one { - my ($r) = @_; - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']); - - $r->print( - '
' - .&Apache::lonhtmlcommon::topic_bar( - 1,&mt('Specify the Course Management system used to create the package')) - .&mt('Please choose the CMS used to create your IMS content package:').' ' - .'' - ); - $r->print( - &Apache::lonhtmlcommon::topic_bar( - 2,&mt('Locate the IMS content package you wish to upload')) - .'' - .'' - .&mt('File:') - .' ' - ); - $r->print( - '
' - .'

' - .'' - .' ' - .'' - .'

' - ); } - -sub display_two { +sub display_one { my ($r,$crs,$areasref,$areaname,%cmsmap) = @_; - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']); my $cms = $env{'form.source'}; my $timenow = time; my $tempdir = &Apache::imsprocessor::create_tempdir('DOCS',$crs,$timenow); @@ -285,10 +225,11 @@ sub display_two { if ($unzip_result ne 'ok') { $r->print( - '

' - .&mt('Processing of your IMS package failed because the file you' - .' uploaded could not be unzipped.') - .'

' + &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(); } @@ -299,23 +240,24 @@ sub display_two { \%resinfo,'choose',\%includedres,\%includeditems); if ($manifest_result ne 'ok') { $r->print( - '

' - .&mt('Unpacking of your IMS package failed because an IMS manifest file was not located in the package.') - .'

' + '
'.&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) { + foreach my $res (sort(keys(%resources))) { if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4') { - foreach my $area (keys %{$cmsmap{$cms}}) { + foreach my $area (keys(%{$cmsmap{$cms}})) { if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) { $count{$area} ++; } } } elsif ($cms eq 'angel5') { - foreach my $area (keys %{$cmsmap{$cms}}) { + foreach my $area (keys(%{$cmsmap{$cms}})) { if ($area eq 'doc') { if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) { $count{$area} ++; @@ -335,12 +277,12 @@ sub display_two { } - # Start output: Step 3 and step 4 + # Start output: Step 1 and step 2 $r->print( - '' + '' .&Apache::lonhtmlcommon::topic_bar( - 3,&mt('Choose which content types you wish to import')) + 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:') .'

' @@ -410,7 +352,7 @@ sub display_two { $r->print( &Apache::lonhtmlcommon::topic_bar( - 4,&mt('Choose display options for listing of contents of top level of package')) + 2,&mt('Choose display options for listing of contents of top level of package')) .'

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

' @@ -433,7 +375,7 @@ sub display_two { '' .'' .'' - .'' + .'' ); $r->print( '
' @@ -449,16 +391,11 @@ sub display_two { $r->print('
'); } - -sub display_three { +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 %importareas = (); my %includedres = (); my %includeditems = (); @@ -516,16 +453,16 @@ sub display_three { 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) { + foreach my $res (sort(keys(%resources))) { if ($importareas{$resources{$res}{type}}) { $includedres{$res} = 1; } } - foreach my $itm (sort keys %items) { + foreach my $itm (sort(keys(%items))) { &Apache::imsprocessor::get_imports(\%includeditems,\%items,\%resources,\%importareas,$itm); } } - foreach my $itm (sort keys %includeditems) { + foreach my $itm (sort(keys(%includeditems))) { &Apache::imsprocessor::get_parents(\%includeditems,\%items,$itm); } @@ -563,7 +500,7 @@ sub display_three { &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,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\%importareas); + 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); @@ -619,8 +556,8 @@ sub display_three { # Re-initialize Button my $initbutton = ''; + .&mt('re-initializing Course') + .'" onclick="javascript:init(this.form)" />'; $r->print( '
' .''