--- loncom/imspackages/imsimport.pm 2013/07/15 16:13:16 1.42
+++ 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.42 2013/07/15 16:13:16 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\\n")
newWindow.document.write("
\\n")
newWindow.document.write("
\\n")
- newWindow.document.write("
$lt{'loca'} $fullpath
$lt{'newd'}
\\n")
+ newWindow.document.write("
$html_lt{'loca'} $fullpath
$html_lt{'newd'}
\\n")
newWindow.document.write("
\\n")
newWindow.document.write("
\\n")
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.').'
@@ -332,12 +352,12 @@ sub display_two {
type => 'Content type',
addo => 'Additional options',
chec => 'Check Import first',
- bbus => 'Choose a course to receive bulletin boards and user enrollment',
- list => 'A listing of possible course targets will be displayed if import of bulletin boards and/or enrollment is checked above (step 3). If you do not plan to import either of these content types, there is no need to specify a course.',
+ bbus => 'Choose a course to receive discussion boards and user enrollment',
+ list => 'A listing of possible course targets will be displayed if import of discussion boards and/or enrollment is checked above (step 3). If you do not plan to import either of these content types, there is no need to specify a course.',
chco => 'Choose course:',
nreq => 'Not required',
- yodo => 'You do not have active course coordinator status in any LON-CAPA courses currently, so bulletin boards and enrollment information included in your IMS package will be discarded, regardless of your import choice for these two items above (step 3).',
- ifyo => "If you wish to import bulletin boards and/or user information into LON-CAPA please click 'Exit now' to quit the current IMS import process, and contact your domain coordinator and request a course coordinator role in a LON-CAPA course into which you can upload bulletin boards and/or enroll users.",
+ yodo => 'You do not have active course coordinator status in any LON-CAPA courses currently, so discussion boards and enrollment information included in your IMS package will be discarded, regardless of your import choice for these two items above (step 3).',
+ ifyo => "If you wish to import discussion boards and/or user information into LON-CAPA please click 'Exit now' to quit the current IMS import process, and contact your domain coordinator and request a course coordinator role in a LON-CAPA course into which you can upload discussion boards and/or enroll users.",
impa => 'Import package',
unpa => 'Unpacking of your IMS package failed because an IMS manifest file was not located in the package',
proc => 'Processing of your IMS package failed because the file you uploaded could not be unzipped',
@@ -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))
+ );
}
}
@@ -543,8 +567,10 @@ sub display_three {
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) {
+ my %possibledep;
+ foreach my $res (sort(keys(%resources))) {
if ($importareas{$resources{$res}{type}}) {
$includedres{$res} = 1;
if ($resources{$res}{type} eq 'webct.manifest' ||
@@ -552,20 +578,28 @@ sub display_three {
$resources{$res}{type} eq 'webct.question') {
push(@assessmentfiles,$res);
}
+ } elsif ($resources{$res}{usedby}) {
+ $possibledep{$res} = 1;
+ }
+ }
+ foreach my $res (sort(keys(%possibledep))) {
+ if ($includedres{$resources{$res}{usedby}}) {
+ $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);
}
$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,\%importareas,\@targets);
@@ -584,24 +618,36 @@ sub display_three {
&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);
- my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\@assessmentfiles,\%total);
+ my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$cms,\%hrefs,\%resources,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\@assessmentfiles,\%total);
&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,bulletin 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,bulletin 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('