--- loncom/imspackages/imsimport.pm 2013/09/23 17:35:05 1.44 +++ loncom/imspackages/imsimport.pm 2023/07/23 13:33:52 1.49 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: imsimport.pm,v 1.44 2013/09/23 17:35:05 bisitz Exp $ +# $Id: imsimport.pm,v 1.49 2023/07/23 13:33:52 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -38,6 +38,7 @@ use HTML::Entities(); use Apache::lonlocal; use Apache::lonupload; use File::Basename(); +use File::Path(); use LONCAPA; # ---------------------------------------------------------------- Jscript One @@ -57,22 +58,26 @@ sub jscript_one { my $end_page = &Apache::loncommon::end_page({'js_ready' => 1,}); - my %lt = &Apache::lonlocal::texthash( + my %js_lt = &Apache::lonlocal::texthash( ddir => 'You must choose a destination directory for the import', cmss => 'You must choose the Course Management System from which the IMS package was exported', + ); + my %html_lt = &Apache::lonlocal::texthash( loca => 'Location:', newd => 'New Directory', nndi => 'Enter the name of the new directory where you will store the contents of your IMS package.', go => 'Go', ); + &js_escape(\%js_lt); + &html_escape(\%html_lt); return <<"END_OF_ONE"; function verify() { if ((document.forms.$formname.newdir.value == '') || (!document.forms.$formname.newdir.value)) { - alert('$lt{'ddir'}') + alert('$js_lt{'ddir'}') return false } if (document.forms.$formname.source.selectedIndex == 0) { - alert('$lt{'cmss'}'); + alert('$js_lt{'cmss'}'); return false } return true @@ -92,15 +97,15 @@ function createWin() { 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("\\n") newWindow.document.write("
  

$lt{'loca'} $fullpath

$lt{'newd'}

$html_lt{'loca'} $fullpath

$html_lt{'newd'}

  
\\n") - newWindow.document.write("$lt{'nndi'}

") + newWindow.document.write("$html_lt{'nndi'}

") 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') @@ -133,6 +138,21 @@ sub jscript_two { $course_list = '"'.join('","',@crslist).'"'; $$numcrs = @crslist; + my %js_lt = &Apache::lonlocal::texthash( + sel => 'Please select', + impto => 'Import topics only', + imptpa => 'Import topics + posts (with author)', + imptpn => 'Import topics + posts (no author)', + enrst => 'Enroll students only', + enrall => 'Enroll all users', + notreq => 'Not required', + errao => 'You must select one of the additional options when importing Discussion Boards.', + errtd => 'You must select a target course when importing Discussion Boards.', + errap => 'You must select one of the additional options when importing Enrollment.', + errte => 'You must select a target course when importing enrollment information.', + errcc => 'You must check at least one Content Type.', + ); + &js_escape(\%js_lt); return <<"END_OF_TWO"; function checkCourse() { @@ -181,7 +201,7 @@ function setCourse(step2Form,call) { step2Form.targetcourse.length = 0 if (call == 'add') { step2Form.targetcourse.length = 0 - step2Form.targetcourse.options[0] = new Option("Please Select","0",true,true) + step2Form.targetcourse.options[0] = new Option("$js_lt{'sel'}","0",true,true) for (var i=0; i 0) { @@ -234,7 +254,7 @@ 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("$js_lt{'errao'}") return false } if (numCrs == 0) { @@ -243,14 +263,14 @@ function verify(caller) { } else { if (opForm.targetcourse.selectedIndex == 0) { - alert("You must select a target course when importing Discussion Boards") + alert("$js_lt{'errtd'}") 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("$js_lt{'errap'}") return false } if (numCrs == 0) { @@ -259,7 +279,7 @@ function verify(caller) { } else { if (opForm.targetcourse.selectedIndex == 0) { - alert("You must select a target course when importing enrollment information") + alert("$js_lt{'errte'}") return false } } @@ -267,7 +287,7 @@ function verify(caller) { } } if (totcheck == 0) { - alert("You must check the Checkbox for at least one Content Type"); + alert("$js_lt{'errcc'}"); return false } return true @@ -290,7 +310,7 @@ sub display_one { &Apache::lonhtmlcommon::topic_bar(1,&mt('Specify the Course Management system used to create the package')). &mt('Choose the CMS used to create your IMS content package.').'  
'."\n". &Apache::lonhtmlcommon::topic_bar(2,&mt('Create a directory where you will unpack your IMS package'))."\n". - &mt('Create a destination LON-CAPA directory in which to store the contents of the IMS package file.').'  

+ &mt('Create a destination LON-CAPA directory in which to store the contents of the IMS package file.').'  

     @@ -364,16 +384,16 @@ sub display_two { $tempdir,\%resources,\%items,\%hrefs,\%resinfo, 'choose',\%includedres,\%includeditems); if ($manifest_result eq 'ok') { - foreach my $res (sort keys %resources) { + foreach my $res (sort(keys(%resources))) { if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4' || $cms eq 'webctvista4') { - 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} ++; @@ -465,7 +485,11 @@ sub display_two { $r->print($lt{'unpa'}); } } else { - $r->print($lt{'proc'}); + $r->print( + '
'.&Apache::loncommon::confirmwrapper( + &Apache::lonhtmlcommon::confirm_success($lt{'proc'},1) + .'
'.&mt('Error: [_1]',$unzip_result)) + ); } } @@ -546,7 +570,7 @@ sub display_three { if ($manifest_result eq 'ok') { my %possibledep; - foreach my $res (sort keys %resources) { + foreach my $res (sort(keys(%resources))) { if ($importareas{$resources{$res}{type}}) { $includedres{$res} = 1; if ($resources{$res}{type} eq 'webct.manifest' || @@ -563,12 +587,12 @@ sub display_three { $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); } @@ -598,20 +622,32 @@ sub display_three { &Apache::imsprocessor::build_structure($cms,'CSTR',$destdir,\%items,\%resinfo,\%resources,\@targets,\%hrefs,$udom,$uname,$dirpath,$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages,\%includeditems,\%randompicks); - $r->print("

IMS import completed

"); + my $message = + &Apache::lonhtmlcommon::confirm_success( + &mt('IMS import completed')) + .'
'.$lt{'yims'}.' '; if ($cms eq 'angel5') { - $r->print($lt{'yims'}.' '.&mt('A total of [quant,_1,sequence], [quant,_2,composite page], and [quant,_3,discussion board] have been created, and [quant,_4,file] copied.',$total{seq},$total{page},$total{board},$total{file})."\n"); + $message .= &mt('A total of [quant,_1,sequence], [quant,_2,composite page], and [quant,_3,discussion board] have been created, and [quant,_4,file] copied.',$total{seq},$total{page},$total{board},$total{file})."\n"; } else { - $r->print($lt{'yims'}.' '.&mt('A total of [quant,_1,sequence], [quant,_2,composite page], [quant,_3,discussion board], [quant,_4,quiz,quizzes], [quant,_5,survey], and [quant,_6,problem] have been created, and [quant,_7,file] copied.',$total{seq},$total{page},$total{board},$total{quiz},$total{surv},$total{prob},$total{file})."\n"); + $message .= &mt('A total of [quant,_1,sequence], [quant,_2,composite page], [quant,_3,discussion board], [quant,_4,quiz,quizzes], [quant,_5,survey], and [quant,_6,problem] have been created, and [quant,_7,file] copied.',$total{seq},$total{page},$total{board},$total{quiz},$total{surv},$total{prob},$total{file})."\n"; } - $r->print('

'.$lt{'plsv'}.' '.$lt{'tseq'}.'

'.$lt{'tfin'}.'

'.$lt{'disp'}.''); + $r->print( + '
'.&Apache::loncommon::confirmwrapper($message) + .'

'.$lt{'plsv'}.' '.$lt{'tseq'}.'

' + .'

'.$lt{'tfin'}.'

' + .&Apache::lonhtmlcommon::actionbox( + [''.$lt{'disp'}.'']) + ); my $londocroot = $r->dir_config('lonDocRoot'); if ($destdir =~ m{^\Q$londocroot/priv/$udom/$uname/$dirpath\E}) { - system (" rm -r -f $destdir/temp"); + &File::Path::remove_tree("$destdir/temp",{ safe => 1 }); } } elsif ($manifest_result eq 'nomanifest') { - $r->print($lt{'proc'}); + $r->print( + '
'.&Apache::loncommon::confirmwrapper( + &Apache::lonhtmlcommon::confirm_success($lt{'proc'},1)) + ); } } @@ -656,7 +692,7 @@ sub get_ccroles { push @{$courses{$currcode}}, $cdom.'/'.$crs; } } - foreach my $code (sort @codes) { + foreach my $code (sort(@codes)) { foreach my $crsdom (@{$courses{$code}}) { my ($cdom,$crs) = split/\//,$crsdom; my $showcode = ''; @@ -737,18 +773,36 @@ END_JS } my $title = 'Upload IMS package to Authoring Space'; + my $crsauthor; + if ($env{'request.course.id'}) { + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + if (($udom eq $cdom) && ($uname eq $cnum)) { + $title = 'Upload IMS package to Course Authoring Space'; + $crsauthor = 1; + } + } + $r->print(&Apache::loncommon::start_page($title, $javascript)); - if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { - $r->print('

' - .&mt('Co-Author [_1]',$uname.':'.$udom) - .'

' - ); + unless ($crsauthor) { + if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { + $r->print('

' + .&mt('Co-Author [_1]',$uname.':'.$udom) + .'

' + ); + } } if ($env{'form.phase'} eq 'two') { my $flag = &Apache::lonupload::phasetwo($r,$fn,'imsimport'); if ($flag eq 'ok') { &display_one($r,$fn,$fullpath,$formname_one); + } else { + $r->print( + '
'.&Apache::loncommon::confirmwrapper( + &Apache::lonhtmlcommon::confirm_success( + &mt('Error uploading IMS package'),1)) + ); } } elsif ( ($env{'form.phase'} eq 'three') || ($env{'form.phase'} eq 'four') ) { my $destdir = $env{'form.newdir'};