--- loncom/imspackages/imsprocessor.pm 2005/07/13 21:21:01 1.26
+++ loncom/imspackages/imsprocessor.pm 2018/05/02 19:34:58 1.58
@@ -1,3 +1,8 @@
+# The LearningOnline Network with CAPA
+# Processor for IMS Packages
+#
+# $Id: imsprocessor.pm,v 1.58 2018/05/02 19:34:58 raeburn Exp $
+#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
@@ -24,15 +29,17 @@
package Apache::imsprocessor;
use Apache::lonnet;
+use Apache::loncommon;
use Apache::loncleanup;
-use LWP::UserAgent;
+use Apache::lonlocal;
use HTTP::Request::Common;
use LONCAPA::Configuration;
+use LONCAPA::LWPReq;
use strict;
sub ims_config {
my ($areas,$cmsmap,$areaname) = @_;
- @{$areas} = ("doc","extlink","announce","staff","board","quiz","survey","pool","users");
+ @{$areas} = ("doc","extlink","announce","staff","board","quiz","survey","pool","users","question");
%{$$cmsmap{bb5}} = (
announce => 'resource/x-bb-announcement',
board => 'resource/x-bb-discussionboard',
@@ -44,28 +51,45 @@ sub ims_config {
survey => 'assessment/x-bb-survey',
users => 'course/x-bb-user',
);
- %{$$cmsmap{bb6}} = %{$$cmsmap{bb5}};
+ %{$$cmsmap{bb6}} = (
+ announce => 'resource/x-bb-announcement',
+ board => 'resource/x-bb-discussionboard',
+ doc => 'resource/x-bb-document',
+ extlink => 'resource/x-bb-externallink',
+ pool => 'assessment/x-bb-qti-pool',
+ quiz => 'assessment/x-bb-qti-test',
+ staff => 'resource/x-bb-staffinfo',
+ survey => 'assessment/x-bb-survey',
+ users => 'course/x-bb-user',
+ );
$$cmsmap{bb6}{conference} = 'resource/x-bb-conference';
- %{$$cmsmap{angel}} = (
+ %{$$cmsmap{angel5}} = (
board => 'BOARD',
extlink => 'LINK',
msg => 'MESSAGE',
quiz => 'QUIZ',
survey => 'FORM',
);
- @{$$cmsmap{angel}{doc}} = ('FILE','PAGE');
- %{$$cmsmap{webct4}} = (
+ @{$$cmsmap{angel5}{doc}} = ('FILE','PAGE');
+ %{$$cmsmap{webctce4}} = (
quiz => 'webctquiz',
survey => 'webctsurvey',
doc => 'webcontent'
);
- %{$areaname} = (
+ %{$$cmsmap{webctvista4}} = (
+ question => 'webct.question',
+ quiz => 'webct.assessment',
+ survey => 'webctsurvey',
+ doc => 'webcontent'
+ );
+ %{$areaname} = &Apache::lonlocal::texthash (
announce => 'Announcements',
board => 'Discussion Boards',
doc => 'Documents, pages, and folders',
extlink => 'Links to external sites',
pool => 'Question pools',
quiz => 'Quizzes',
+ question => 'Assessment Questions',
staff => 'Staff information',
survey => 'Surveys',
users => 'Enrollment',
@@ -76,6 +100,9 @@ sub create_tempdir {
my ($context,$pathinfo,$timenow) = @_;
my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf');
my $tempdir;
+ $pathinfo = &Apache::loncommon::clean_path($pathinfo);
+# Collapse dots
+ $pathinfo =~ s/\.+/./g;
if ($context eq 'DOCS') {
$tempdir = $$configvars{'lonDaemons'}.'/tmp/'.$pathinfo;
if (!-e "$tempdir") {
@@ -107,11 +134,13 @@ sub uploadzip {
$fname=~s/\s+/\_/g;
# Replace all other weird characters by nothing
$fname=~s/[^\w\.\-]//g;
+# Collapse dots
+ $fname=~s/\.+/./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);
+ open(my $fh,'>',"$tempdir/$fname");
print $fh $env{'form.uploadname'};
close($fh);
} elsif ($context eq 'CSTR') {
@@ -147,15 +176,11 @@ sub process_manifest {
my %toc = (
bb6 => 'organization',
bb5 => 'tableofcontents',
- angel => 'organization',
- webct4 => 'organization',
+ angel5 => 'organization',
+ webctce4 => 'organization',
+ webctvista4 => 'organization'
);
- my %contents = ();
- my @state = ();
- my $itm = '';
- my $identifier = '';
my @seq = "Top";
- my $lastitem;
%{$$items{'Top'}} = (
contentscount => 0,
resnum => 'toplevel',
@@ -164,7 +189,7 @@ sub process_manifest {
revitm => 'Top'
);
- if ($cms eq 'angel') {
+ if ($cms eq 'angel5') {
$$resources{'toplevel'}{type} = "FOLDER";
} elsif ($cms eq 'bb5' || $cms eq 'bb6') {
$$resources{'toplevel'}{type} = 'resource/x-bb-document';
@@ -177,6 +202,21 @@ sub process_manifest {
}
my $xmlfile = $tempdir.'/imsmanifest.xml';
+ &parse_manifest($cms,$phase,$tempdir,$xmlfile,\%toc,$includedres,
+ $includeditems,$items,$resources,$resinfo,$hrefs,\@seq);
+ return 'ok' ;
+}
+
+sub parse_manifest {
+ my ($cms,$phase,$tempdir,$xmlfile,$toc,$includedres,$includeditems,$items,
+ $resources,$resinfo,$hrefs,$seq,$requirer) = @_;
+ my @state = ();
+ my $itm = '';
+ my %contents = ();
+ my $identifier = '';
+ my @allidentifiers = ();
+ my $lastitem;
+ my $neededby;
my $p = HTML::Parser->new
(
xml_mode => 1,
@@ -185,53 +225,53 @@ sub process_manifest {
my ($tagname, $attr) = @_;
push @state, $tagname;
my $start = @state - 3;
- if ( ($state[0] eq "manifest") && ($state[1] eq "organizations") && ($state[2] eq $toc{$cms}) ) {
+ if ( ($state[0] eq "manifest") && ($state[1] eq "organizations") && ($state[2] eq $$toc{$cms}) ) {
if ($state[-1] eq 'item') {
$itm = $attr->{identifier};
if ($$includeditems{$itm} || $phase ne 'build') {
%{$$items{$itm}} = ();
$$items{$itm}{contentscount} = 0;
@{$$items{$itm}{contents}} = ();
- if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webct4') {
+ if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4' || $cms eq 'webctvista4') {
$$items{$itm}{resnum} = $attr->{identifierref};
if ($cms eq 'bb5') {
$$items{$itm}{title} = $attr->{title};
}
- } elsif ($cms eq 'angel') {
+ } elsif ($cms eq 'angel5') {
if ($attr->{identifierref} =~ m/^res(.+)$/) {
$$items{$itm}{resnum} = $1;
}
}
- unless (defined(%{$$resources{$$items{$itm}{resnum}}}) ) {
+ unless (%{$$resources{$$items{$itm}{resnum}}}) {
%{$$resources{$$items{$itm}{resnum}}} = ();
}
$$resources{$$items{$itm}{resnum}}{revitm} = $itm;
- if ($start > @seq) {
+ if ($start > @{$seq}) {
unless ($lastitem eq '') {
- push @seq, $lastitem;
- unless ( defined($contents{$seq[-1]}) ) {
- @{$contents{$seq[-1]}} = ();
+ push @{$seq}, $lastitem;
+ unless ( defined($contents{$$seq[-1]}) ) {
+ @{$contents{$$seq[-1]}} = ();
}
- push @{$contents{$seq[-1]}},$itm;
- $$items{$itm}{parentseq} = $seq[-1];
+ push @{$contents{$$seq[-1]}},$itm;
+ $$items{$itm}{parentseq} = $$seq[-1];
}
- } elsif ($start < @seq) {
- my $diff = @seq - $start;
+ } elsif ($start < @{$seq}) {
+ my $diff = @{$seq} - $start;
while ($diff > 0) {
- pop @seq;
+ pop @{$seq};
$diff --;
}
- if (@seq) {
- push @{$contents{$seq[-1]}}, $itm;
+ if (@{$seq}) {
+ push @{$contents{$$seq[-1]}}, $itm;
}
} else {
- push @{$contents{$seq[-1]}}, $itm;
+ push @{$contents{$$seq[-1]}}, $itm;
}
my $path;
- if (@seq > 1) {
- $path = join(',',@seq);
- } elsif (@seq > 0) {
- $path = $seq[0];
+ if (@{$seq} > 1) {
+ $path = join(',',@{$seq});
+ } elsif (@{$seq} > 0) {
+ $path = $$seq[0];
}
$$items{$itm}{filepath} = $path;
if ($cms eq 'bb5' || $cms eq 'bb6') {
@@ -242,25 +282,30 @@ sub process_manifest {
$$resinfo{$$items{$itm}{resnum}}{'isfolder'} = 'true';
}
}
- $$items{$seq[-1]}{contentscount} ++;
+ $$items{$$seq[-1]}{contentscount} ++;
+ $$resources{$$items{$itm}{resnum}}{seqref} = $seq;
$lastitem = $itm;
}
}
- if ($cms eq 'webct4') {
+ if ($cms eq 'webctce4') {
if (($state[-1] eq "webct:properties") && (@state > 4)) {
$$items{$itm}{properties} = $attr->{identifierref};
}
}
} elsif ("@state" eq "manifest resources resource" ) {
$identifier = $attr->{identifier};
+ push(@allidentifiers,$identifier);
if ($$includedres{$identifier} || $phase ne 'build') {
if ($cms eq 'bb5' || $cms eq 'bb6') {
$$resources{$identifier}{file} = $attr->{file};
$$resources{$identifier}{type} = $attr->{type};
- } elsif ($cms eq 'webct4') {
+ } elsif ($cms eq 'webctce4') {
$$resources{$identifier}{type} = $attr->{type};
$$resources{$identifier}{file} = $attr->{href};
- } elsif ($cms eq 'angel') {
+ } elsif ($cms eq 'webctvista4') {
+ $$resources{$identifier}{type} = $attr->{type};
+ $$resources{$identifier}{'webct:coType'} = $attr->{'webct:coType'};
+ } elsif ($cms eq 'angel5') {
$identifier = substr($identifier,3);
if ($attr->{href} =~ m-^_assoc/$identifier/(.+)$-) {
$$resources{$identifier}{file} = $1;
@@ -270,9 +315,34 @@ sub process_manifest {
}
} elsif ("@state" eq "manifest resources resource file") {
if ($$includedres{$identifier} || $phase ne 'build') {
- if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webct4') {
- push @{$$hrefs{$identifier}},$attr->{href};
- } elsif ($cms eq 'angel') {
+ if ($cms eq 'bb5' || $cms eq 'bb6' ||
+ $cms eq 'webctce4' || $cms eq 'webctvista4') {
+ if ($$resources{$identifier}{type} eq
+ 'webct.manifest') {
+ my $manifestfile = $tempdir.'/'.$attr->{href};
+ my $currseqref = [];
+ if ($itm) {
+ $currseqref =
+ $$resources{$$items{$itm}{resnum}}{seqref};
+ }
+ &parse_manifest($cms,$phase,$tempdir,$manifestfile,
+ $toc,$includedres,$includeditems,
+ $items,$resources,$resinfo,
+ $hrefs,$currseqref,$neededby);
+ } else {
+ if ($cms eq 'webctvista4') {
+ if ($$resources{$identifier}{type} eq 'ims_qtiasiv1p2') {
+ $neededby = $identifier;
+ } elsif ($$resources{$identifier}{type} eq 'webcontent') {
+ $$resources{$identifier}{usedby} = $requirer;
+ push(@{$$hrefs{$identifier}},$attr->{href});
+ }
+ $$resources{$identifier}{file} = $attr->{href};
+ } else {
+ push(@{$$hrefs{$identifier}},$attr->{href});
+ }
+ }
+ } elsif ($cms eq 'angel5') {
if ($attr->{href} =~ m/^_assoc\\$identifier\\(.+)$/) {
push @{$$hrefs{$identifier}},$1;
} elsif ($attr->{href} =~ m/^Icons\\icon(\w+)\.gif/) {
@@ -280,6 +350,12 @@ sub process_manifest {
}
}
}
+ } elsif ("@state" eq "manifest webct:ContentObject") {
+ foreach my $ident (@allidentifiers) {
+ if ($$resources{$ident}{type} eq 'ims_qtiasiv1p2') {
+ $$resources{$ident}{type} = $attr->{'webct:coType'};
+ }
+ }
}
}, "tagname, attr"],
text_h =>
@@ -288,17 +364,26 @@ sub process_manifest {
if ("@state" eq "manifest metadata lom general title langstring") {
$$items{'Top'}{title} = $text;
}
- if ($state[0] eq "manifest" && $state[1] eq "organizations" && $state[2] eq $toc{$cms} && $state[-1] eq "title") {
+ if ($state[0] eq "manifest" && $state[1] eq "organizations" && $state[2] eq $$toc{$cms} && $state[-1] eq "title") {
if ($$includeditems{$itm} || $phase ne 'build') {
- if ($cms eq 'angel' || $cms eq 'bb6') {
+ if ($cms eq 'angel5' || $cms eq 'bb6' || $cms eq 'webctvista4') {
$$items{$itm}{title} = $text;
}
- if ($cms eq 'webct4') {
+ if ($cms eq 'webctce4') {
$$items{$itm}{title} = $text;
$$items{$itm}{title} =~ s/(<[^>]*>)//g;
}
}
}
+ if ("@state" eq "manifest webct:ContentObject webct:Name") {
+ if ($cms eq 'webctvista4') {
+ if ($text =~ /,/) {
+ $$resources{$identifier}{title} = (split(/,/,$text))[-1];
+ } else {
+ $$resources{$identifier}{title} = $text;
+ }
+ }
+ }
}, "dtext"],
end_h =>
[sub {
@@ -308,11 +393,9 @@ sub process_manifest {
);
$p->parse_file($xmlfile);
$p->eof;
-
- foreach my $itm (keys %contents) {
+ foreach my $itm (keys(%contents)) {
@{$$items{$itm}{contents}} = @{$contents{$itm}};
}
- return 'ok' ;
}
sub get_imports {
@@ -346,44 +429,58 @@ sub get_parents {
sub target_resources {
my ($resources,$oktypes,$targets) = @_;
- foreach my $key (keys %{$resources}) {
+ foreach my $key (sort(keys(%{$resources}))) {
if ( defined($$oktypes{$$resources{$key}{type}}) ) {
- push @{$targets}, $key;
+ push(@{$targets},$key);
+ } elsif (defined($$resources{$key}{usedby})) {
+ if (defined($$oktypes{$$resources{$$resources{$key}{usedby}}{type}})) {
+ push(@{$targets},$key);
+ }
}
}
return;
}
sub copy_resources {
- my ($context,$cms,$hrefs,$tempdir,$targets,$url,$crs,$cdom,$chome,$destdir,$timenow) = @_;
+ my ($context,$cms,$hrefs,$resources,$tempdir,$targets,$url,$crs,$cdom,$destdir,$timenow,$assessmentfiles,$total) = @_;
if ($context eq 'DOCS') {
- foreach my $key (sort keys %{$hrefs}) {
+ foreach my $key (sort(keys(%{$hrefs}))) {
if (grep/^$key$/,@{$targets}) {
%{$$url{$key}} = ();
foreach my $file (@{$$hrefs{$key}}) {
my $source = $tempdir.'/'.$key.'/'.$file;
- if ($cms eq 'webct4') {
+ if ($cms eq 'webctce4' || $cms eq 'webctvista4') {
$source = $tempdir.'/'.$file;
}
my $filename = '';
my $fpath = $timenow.'/resfiles/'.$key.'/';
- if ($cms eq 'angel') {
+ if ($cms eq 'angel5') {
if ($file eq 'pg'.$key.'.htm') {
next;
}
}
$file =~ s-\\-/-g;
my $copyfile = $file;
- if ($cms eq 'webct4') {
+ if ($cms eq 'webctce4' || $cms eq 'webctvista4') {
if ($file =~ m-/my_files/(.+)$-) {
$copyfile = $1;
}
}
- unless (($cms eq 'webct4') && ($copyfile =~ m/questionDB\.xml$/ || $copyfile =~ m/quiz_QIZ_\d+\.xml$/ || $copyfile =~ m/properties_QIZ_\d+\.xml$/)) {
+ if ($cms eq 'webctvista4') {
+ if ($file =~ m{/\QX-WEBCT-VISTA-V0\E/.+([^.]+)$}) {
+ $copyfile = $1;
+ }
+ if ($$resources{$key}{usedby}) {
+ if ($$resources{$$resources{$key}{usedby}}{image} =~ /^\Q$copyfile\E/) {
+ $copyfile = $$resources{$$resources{$key}{usedby}}{image};
+ }
+ }
+ }
+ unless ((($cms eq 'webctce4') && ($copyfile =~ m/questionDB\.xml$/ || $copyfile =~ m/quiz_QIZ_\d+\.xml$/ || $copyfile =~ m/properties_QIZ_\d+\.xml$/)) || (($cms eq 'webctvista4') && (grep/^$key$/,@{$assessmentfiles}) && $file =~ /\.xml$/)) {
$copyfile = $fpath.$copyfile;
my $fileresult;
if (-e $source) {
- $fileresult = &Apache::lonnet::process_coursefile('copy',$crs,$cdom,$chome,$copyfile,$source);
+ $fileresult = &Apache::lonnet::process_coursefile('copy',$crs,$cdom,$copyfile,$source);
}
}
}
@@ -393,11 +490,11 @@ sub copy_resources {
if (!-e "$destdir/resfiles") {
mkdir("$destdir/resfiles",0770);
}
- foreach my $key (sort keys %{$hrefs}) {
+ foreach my $key (sort(keys(%{$hrefs}))) {
if (grep/^$key$/,@{$targets}) {
foreach my $file (@{$$hrefs{$key}}) {
$file =~ s-\\-/-g;
- if ( ($cms eq 'angel' && $file ne 'pg'.$key.'.htm') || ($cms eq 'bb5') || ($cms eq 'bb6')) {
+ if ( ($cms eq 'angel5' && $file ne 'pg'.$key.'.htm') || ($cms eq 'bb5') || ($cms eq 'bb6')) {
if (!-e "$destdir/resfiles/$key") {
mkdir("$destdir/resfiles/$key",0770);
}
@@ -412,12 +509,20 @@ sub copy_resources {
mkdir("$fulldir",0770);
}
}
- if ($cms eq 'angel') {
- rename("$tempdir/_assoc/$key/$file","$destdir/resfiles/$key/$file");
+ my $renameres;
+ if ($cms eq 'angel5') {
+ $renameres = rename("$tempdir/_assoc/$key/$file","$destdir/resfiles/$key/$file");
} elsif ($cms eq 'bb5' || $cms eq 'bb6') {
- rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file");
+ $renameres = rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file");
}
- } elsif ($cms eq 'webct4') {
+ if ($renameres) {
+ if (ref($total) eq 'HASH') {
+ $$total{'file'} ++;
+ }
+ } else {
+ &Apache::lonnet::logthis("IMS import error: $cms - renaming failed for file $file");
+ }
+ } elsif ($cms eq 'webctce4') {
if ($file =~ m-/my_files/(.+)$-) {
my $copyfile = $1;
if ($copyfile =~ m-^[^/]+/[^/]+-) {
@@ -432,11 +537,64 @@ sub copy_resources {
}
}
if (-e "$tempdir/$file") {
- rename("$tempdir/$file","$destdir/resfiles/$copyfile");
+ my $renameres = rename("$tempdir/$file","$destdir/resfiles/$copyfile");
+ if ($renameres) {
+ if (ref($total) eq 'HASH') {
+ $$total{'file'} ++;
+ }
+ } else {
+ &Apache::lonnet::logthis("IMS import error: WebCT4 - renaming failed for file $file");
+ }
}
} elsif ($file !~ m-/data/(.+)$-) {
&Apache::lonnet::logthis("IMS import error: WebCT4 - file $file is in unexpected location");
}
+ } elsif ($cms eq 'webctvista4') {
+ if ($file =~ m{^\QX-WEBCT-VISTA-V0\E/(.+)$}) {
+ my $copyfile = $1;
+ if ($copyfile =~ m{^[^/]+/[^/]+}) {
+ my @dirs = split/\//,$copyfile;
+ my $path = "$destdir/resfiles";
+ while (@dirs > 1) {
+ $path .= '/'.$dirs[0];
+ if (!-e "$path") {
+ mkdir("$path",0755);
+ }
+ shift @dirs;
+ }
+ } else {
+ $copyfile =~ s/^[^.]+\.(\d+)_R/$1/;
+ my ($filestem,$extension) = ($copyfile =~ /^(.+)\.(\w+)$/);
+ if ($$resources{$key}{usedby}) {
+ if (ref($$resources{$$resources{$key}{usedby}}{image}) eq 'ARRAY') {
+ for (my $i=0; $i<@{$$resources{$$resources{$key}{usedby}}{image}}; $i++) {
+ my ($img,$imgtitle);
+ $img = $$resources{$$resources{$key}{usedby}}{image}[$i];
+ if (ref($$resources{$$resources{$key}{usedby}}{imagetitle}) eq 'ARRAY') {
+ $imgtitle = $$resources{$$resources{$key}{usedby}}{imagetitle}[$i];
+ }
+ if ($imgtitle =~ /\Q$extension\E/i) {
+ $copyfile = $imgtitle;
+ last;
+ } elsif ($img =~ /^\Q$filestem\E/i) {
+ $copyfile = $img.'.'.$extension;
+ last;
+ }
+ }
+ }
+ }
+ }
+ if (-e "$tempdir/$file") {
+ my $renameres = rename("$tempdir/$file","$destdir/resfiles/$copyfile");
+ if ($renameres) {
+ if (ref($total) eq 'HASH') {
+ $$total{'file'} ++;
+ }
+ } else {
+ &Apache::lonnet::logthis("IMS import error: WebCTVista - renaming failed for file $file");
+ }
+ }
+ }
}
}
}
@@ -451,6 +609,8 @@ sub process_resinfo {
my $dbparse = 0;
my $announce_handling = 'include';
my $longcrs = '';
+ my %allassessments = ();
+ my %allquestions = ();
my %qzdbsettings = ();
my %catinfo = ();
if ($crs =~ m/^(\d)(\d)(\d)/) {
@@ -461,9 +621,9 @@ sub process_resinfo {
mkdir("$destdir/resfiles",0770);
}
}
- if ($cms eq 'angel') {
+ if ($cms eq 'angel5') {
my $currboard = '';
- foreach my $key (sort keys %{$resources}) {
+ foreach my $key (sort(keys(%{$resources}))) {
if (grep/^$key$/,@{$targets}) {
if ($$resources{$key}{type} eq "BOARD") {
push @{$boards}, $key;
@@ -492,7 +652,7 @@ sub process_resinfo {
}
}
} elsif ($cms eq 'bb5' || $cms eq 'bb6') {
- foreach my $key (sort keys %{$resources}) {
+ foreach my $key (sort(keys(%{$resources}))) {
if (grep/^$key$/,@{$targets}) {
if ($$resources{$key}{type} eq "resource/x-bb-document") {
unless ($$items{$$resources{$key}{revitm}}{filepath} eq 'Top') {
@@ -501,10 +661,10 @@ sub process_resinfo {
}
} elsif ($$resources{$key}{type} eq "resource/x-bb-staffinfo") {
%{$$resinfo{$key}} = ();
- &process_staff($key,$docroot,$dirname,$destdir,\%{$$resinfo{$key}},$resrcfiles);
+ &process_staff($key,$docroot,$destdir,\%{$$resinfo{$key}},$resrcfiles);
} elsif ($$resources{$key}{type} eq "resource/x-bb-externallink") {
%{$$resinfo{$key}} = ();
- &process_link($key,$docroot,$dirname,$destdir,\%{$$resinfo{$key}},$resrcfiles);
+ &process_link($key,$docroot,$destdir,\%{$$resinfo{$key}},$resrcfiles);
} elsif ($$resources{$key}{type} eq "resource/x-bb-discussionboard") {
%{$$resinfo{$key}} = ();
unless ($db_handling eq 'ignore') {
@@ -514,17 +674,17 @@ sub process_resinfo {
$board_id ++;
$board_count ++;
}
- } elsif ($$resources{$key}{type} eq "assessment/x-bb-pool") {
+ } elsif ($$resources{$key}{type} =~/assessment\/x\-bb\-(qti\-)?pool/) {
%{$$resinfo{$key}} = ();
- &process_assessment($cms,$context,$key,$docroot,'pool',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs);
+ &process_assessment($cms,$context,$key,$docroot,'pool',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs,\%allquestions);
push @{$pools}, $key;
- } elsif ($$resources{$key}{type} eq "assessment/x-bb-quiz") {
+ } elsif ($$resources{$key}{type} =~ /assessment\/x\-bb\-(qti\-)?quiz/) {
%{$$resinfo{$key}} = ();
- &process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs);
+ &process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs,\%allquestions);
push @{$quizzes}, $key;
- } elsif ($$resources{$key}{type} eq "assessment/x-bb-survey") {
+ } elsif ($$resources{$key}{type} =~ /assessment\/x\-bb\-(qti\-)?survey/) {
%{$$resinfo{$key}} = ();
- &process_assessment($cms,$context,$key,$docroot,'survey',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs);
+ &process_assessment($cms,$context,$key,$docroot,'survey',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs,\%allquestions);
push @{$surveys}, $key;
} elsif ($$resources{$key}{type} eq "assessment/x-bb-group") {
%{$$resinfo{$key}} = ();
@@ -559,17 +719,63 @@ sub process_resinfo {
if (@{$pools}) {
$$items{'Top'}{'contentscount'} ++;
}
- } elsif ($cms eq 'webct4') {
- foreach my $key (sort keys %{$resources}) {
+ } elsif ($cms eq 'webctce4') {
+ foreach my $key (sort(keys(%{$resources}))) {
if (grep/^$key$/,@{$targets}) {
if ($$resources{$key}{type} eq "webcontent") {
%{$$resinfo{$key}} = ();
- &webct4_content($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$$resources{$key}{type},$$items{$$resources{$key}{revitm}}{title},$resrcfiles);
+ if ($$resources{$key}{file} eq 'questiondb.xml') {
+ &process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs,\%allquestions);
+ } else {
+ &webct4_content($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$$resources{$key}{type},$$items{$$resources{$key}{revitm}}{title},$resrcfiles);
+ }
} elsif ($$resources{$key}{type} eq "webctquiz") {
- &process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs);
+ &process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs,\%allquestions);
}
}
}
+ } elsif ($cms eq 'webctvista4') {
+ foreach my $key (sort(keys(%{$resources}))) {
+ if (grep/^$key$/,@{$targets}) {
+ %{$$resinfo{$key}} = ();
+ if ($$resources{$key}{type} eq 'webct.question') {
+ $allquestions{$key} = 1;
+ } elsif ($$resources{$key}{type} eq 'webct.assessment') {
+ $allassessments{$key} = 1;
+ }
+ }
+ }
+ if (keys(%allassessments) > 0) {
+ foreach my $key (sort(keys(%allassessments))) {
+ &process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs,\%allquestions);
+ }
+ } elsif (keys(%allquestions) > 0) {
+ my %catinfo = ();
+ my @allids = ();
+ my @allquestids = ();
+ my %allanswers = ();
+ my %allchoices = ();
+ my $containerdir;
+ my $newdir;
+ my $cid;
+ my $randompickflag = 0;
+ if ($context eq 'DOCS') {
+ $cid = $env{'request.course.id'};
+ }
+ my $destresdir = $destdir;
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ if ($context eq 'CSTR') {
+ $destresdir =~ s{^\Q$londocroot/priv/\E}{/res/};
+ } elsif ($context eq 'DOCS') {
+ $destresdir =~ s{^\Q$londocroot/userfiles\E}{/uploaded};
+ }
+ foreach my $res (sort(keys(%allquestions))) {
+ my $parent = $allquestions{$res};
+ &parse_webctvista4_question($res,$docroot,$resources,$hrefs,\%qzdbsettings,\@allquestids,\%allanswers,\%allchoices,$parent,\%catinfo);
+ }
+ &build_category_sequences($destdir,\%catinfo,$sequencesfiles,$pagesfiles,$destresdir,$newdir,$cms,$total,$randompickflag,$context,$udom,$uname,$dirname,$cid,$cdom,$crs,\%qzdbsettings);
+ &write_webct4_questions($cms,\@allquestids,$context,\%qzdbsettings,$dirname,\%allanswers,\%allchoices,$total,$cid,$cdom,$crs,$destdir,\%catinfo);
+ }
}
$$total{'board'} = $board_count;
@@ -616,7 +822,7 @@ sub build_structure {
$srcstem = "/res/$udom/$uname/$newdir";
}
- foreach my $key (sort keys %{$items}) {
+ foreach my $key (sort(keys(%{$items}))) {
if ($$includeditems{$key}) {
%{$flag{$key}} = (
page => 0,
@@ -638,8 +844,12 @@ sub build_structure {
my $curr_id = 1;
my $resnum = $$items{$key}{resnum};
my $type = $$resources{$resnum}{type};
- my $contentscount = $$items{$key}{'contentscount'};
- if (($cms eq 'angel' && $type eq "FOLDER") || (($cms eq 'bb5' || $cms eq 'bb6') && $$resinfo{$resnum}{'isfolder'} eq "true") && (($type eq "resource/x-bb-document") || ($type eq "resource/x-bb-staffinfo") || ($type eq "resource/x-bb-externallink")) || ($cms eq 'webct4' && $contentscount > 0)) {
+ my $contentscount = $$items{$key}{'contentscount'};
+ my $seqtitle = $$items{$key}{'title'};
+ $seqtitle =~ s|/+|_|g;
+ $seqtitle =~ s/\s+/_/g;
+ $seqtitle .= '_'.$key;
+ if (($cms eq 'angel5' && $type eq "FOLDER") || (($cms eq 'bb5' || $cms eq 'bb6') && $$resinfo{$resnum}{'isfolder'} eq "true") && (($type eq "resource/x-bb-document") || ($type eq "resource/x-bb-staffinfo") || ($type eq "resource/x-bb-externallink")) || ($cms eq 'webctce4' && $contentscount > 0)) {
unless (($cms eq 'bb5') && $key eq 'Top') {
$seqtext{$key} = "\n";
- open(LOCFILE,">$destdir/sequences/$key.sequence");
+ if ($cms eq 'webctce4' && $key ne 'Top') {
+ push @{$seqfiles}, "$seqtitle.sequence";
+ open(LOCFILE,'>',"$destdir/sequences/$seqtitle.sequence");
+ } else {
+ push @{$seqfiles}, "$key.sequence";
+ open(LOCFILE,'>',"$destdir/sequences/$key.sequence");
+ }
print LOCFILE $seqtext{$key};
close(LOCFILE);
- push @{$seqfiles}, "$key.sequence";
}
$count{$key}{page} ++;
$$total{page} += $count{$key}{page};
@@ -812,7 +1027,7 @@ sub build_structure {
&process_specials($context,'pools',$pools,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames);
}
$seqtext{'Top'} .= "\n";
- open(TOPFILE,">$destdir/sequences/Top.sequence");
+ open(TOPFILE,'>',"$destdir/sequences/Top.sequence");
print TOPFILE $seqtext{'Top'};
close(TOPFILE);
push @{$seqfiles}, 'Top.sequence';
@@ -825,7 +1040,7 @@ sub build_structure {
$filestem = "/res/$udom/$uname/$newdir";
}
- foreach my $key (sort keys %pagecontents) {
+ foreach my $key (sort(keys(%pagecontents))) {
for (my $i=0; $i<@{$pagecontents{$key}}; $i++) {
my $filename = $destdir.'/pages/'.$key.'_'.$i.'.page';
my $resource = "$filestem/resfiles/$$items{$pagecontents{$key}[$i][0]}{resnum}.html";
@@ -834,7 +1049,7 @@ sub build_structure {
if (grep/^$res$/,@{$packages}) {
$resource = $filestem.'/resfiles/'.$res.'./index.html'; # should be entry_point
}
- open(PAGEFILE,">$filename");
+ open(PAGEFILE,'>',$filename);
print PAGEFILE qq||;
- if (!-e "$destdir/problems") {
- mkdir("$destdir/problems",0755);
- }
- if (!-e "$destdir/problems/$seqname") {
- mkdir("$destdir/problems/$seqname",0755);
- }
- $newdir = "$destdir/problems/$seqname";
- my $dbcontainerdir;
- &build_problem_container($cms,$seqname,$destdir,'database',$seqname,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,\@{$$catinfo{$category}{contents}},$udom,$uname,$dirname,\$dbcontainerdir,$cid,$cdom,$cnum,$catinfo,$qzdbsettings);
- }
- close($fh);
- &write_webct4_questions(\@alldbquestids,$context,$qzdbsettings,$dirname,\%alldbanswers,\%alldbchoices,$total,$cid,$cdom,$cnum,$destdir,$catinfo);
+ &build_category_sequences($destdir,$catinfo,$sequencesfiles,$pagesfiles,$destresdir,$newdir,$cms,$total,$randompickflag,$context,$udom,$uname,$dirname,$cid,$cdom,$cnum,$qzdbsettings);
+ &write_webct4_questions($cms,\@alldbquestids,$context,$qzdbsettings,$dirname,\%alldbanswers,\%alldbchoices,$total,$cid,$cdom,$cnum,$destdir,$catinfo);
$$dbparse = 1;
}
&parse_webct4_assessment($res,$docroot,$$resources{$res}{file},$container,\@allids);
@@ -2361,11 +3344,26 @@ sub process_assessment {
$randompickflag = 1;
}
}
+ } elsif ($cms eq 'webctvista4') {
+ unless($$dbparse) {
+ foreach my $res (sort(keys(%{$allquestions}))) {
+ my $parent = $$allquestions{$res};
+ &parse_webctvista4_question($res,$docroot,$resources,$hrefs,$qzdbsettings,\@allquestids,\%allanswers,\%allchoices,$parent,$catinfo);
+ }
+ &build_category_sequences($destdir,$catinfo,$sequencesfiles,$pagesfiles,$destresdir,$newdir,$cms,$total,$randompickflag,$context,$udom,$uname,$dirname,$cid,$cdom,$cnum,$qzdbsettings);
+ $$dbparse = 1;
+ }
+ &parse_webctvista4_assessment($res,$docroot,$$resources{$res}{file},\@allids,\%qzparams);
+ if ($qzparams{$res}{numpick} < @allids) {
+ $$randompicks{$$resources{$res}{revitm}} = $qzparams{$res}{numpick};
+ $randompickflag = 1;
+ }
}
my $dirtitle;
- unless ($cms eq 'webct4') {
+ unless ($cms eq 'webctce4' || $cms eq 'webctvista4') {
$dirtitle = $$settings{'title'};
- $dirtitle =~ s/\W//g;
+ $dirtitle =~ s/\s+/_/g;
+ $dirtitle =~ s/:/_/g;
$dirtitle .= '_'.$res;
if (!-e "$destdir/problems") {
mkdir("$destdir/problems",0755);
@@ -2376,41 +3374,108 @@ sub process_assessment {
$newdir = "$destdir/problems/$dirtitle";
}
- if ($cms eq 'webct4') {
- &build_problem_container($cms,$dirtitle,$destdir,$container,$res,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,\@allids,$udom,$uname,$dirname,\$containerdir,$cid,$cdom,$cnum,$catinfo,$qzdbsettings);
+ if ($cms eq 'webctce4') {
+ if (@allids > 0 && $allids[0] ne '') {
+ &build_problem_container($cms,$dirtitle,$destdir,$container,$res,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,\@allids,$udom,$uname,$dirname,\$containerdir,$cid,$cdom,$cnum,$catinfo,$qzdbsettings);
+ }
} else {
- &build_problem_container($cms,$dirtitle,$destdir,$container,$res,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,\@allids,$udom,$uname,$dirname,\$containerdir,$cid,$cdom,$cnum,$catinfo,$settings);
+ &build_problem_container($cms,$dirtitle,$destdir,$container,$res,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,\@allids,$udom,$uname,$dirname,\$containerdir,$cid,$cdom,$cnum,$catinfo,$qzdbsettings,\%qzparams);
}
if ($cms eq 'bb5') {
&write_bb5_questions(\@allids,$containerdir,$context,$settings,$dirname,$destdir,$res,\%allanswers,\%allchoices,$total,$newdir,$cid,$cdom,$cnum,$docroot);
} elsif ($cms eq 'bb6') {
- &write_bb6_questions(\@allids,$containerdir,$context,$settings,$dirname,$destdir,$res,\%allanswers,\%allchoices,$total,$newdir,$cid,$cdom,$cnum);
+ &write_bb6_questions(\@allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$total,$newdir,$cid,$cdom,$cnum,$docroot);
+ } elsif ($cms eq 'webctvista4') {
+ &write_webct4_questions($cms,\@allquestids,$context,$qzdbsettings,$dirname,\%allanswers,\%allchoices,$total,$cid,$cdom,$cnum,$destdir,$catinfo,$dirtitle);
}
}
+sub build_category_sequences {
+ my ($destdir,$catinfo,$sequencesfiles,$pagesfiles,$destresdir,$newdir,$cms,$total,$randompickflag,$context,$udom,$uname,$dirname,$cid,$cdom,$cnum,$qzdbsettings) = @_;
+ if (!-e "$destdir/sequences") {
+ mkdir("$destdir/sequences",0755);
+ }
+ my $numcats = scalar(keys(%{$catinfo}));
+ my $curr_id = 0;
+ my $next_id = 1;
+ my $fh;
+ open($fh,'>',"$destdir/sequences/question_database.sequence");
+ push @{$sequencesfiles},'question_database.sequence';
+ foreach my $category (sort(keys(%{$catinfo}))) {
+ my $seqname;
+ if ($cms eq 'webctce4') {
+ $seqname = $$catinfo{$category}{title}.'_'.$category;
+ } else {
+ $seqname = $$catinfo{$category}{title};
+ }
+ $seqname =~ s/\s+/_/g;
+ $seqname =~ s/:/_/g;
+ push(@{$sequencesfiles},$seqname.'.sequence');
+ my $catsrc = "$destresdir/sequences/$seqname.sequence";
+ if ($curr_id == 0) {
+ print $fh qq|
#
#g;
- $$settings{$id}{text} =~ s#
$$settings{$id}{text}
$questionimage'.$$settings{$id}{text}.'
'.$questionimage; $resourcedata{$symb.'hiddenparts'} = '!essay'; $resourcedata{$symb.'questiontype'} = 'essay'; } + } elsif ($$settings{$id}{class} eq 'jumbled') { + if ($context eq 'CSTR') { + my %foiloptions = (); + foreach my $list (@{$$settings{$id}{lists}}) { + @{$foiloptions{$list}} = (); + my $numalternates = @{$$settings{$id}{$list}{jumbled}} - 1; + my $loopstop = 2; #Hard coded for now, so only one permutation of answers is correct;$$settings{$id}{text}
$questionimage'.$$settings{$id}{text}.'
'.$questionimage; } - if ($$settings{$id}{class} eq 'multiplechoice') { + if (($$settings{$id}{class} eq 'multiplechoice') || + ($$settings{$id}{class} eq 'combination')) { foreach my $list (@{$$settings{$id}{lists}}) { my $numfoils = @{$$allanswers{$id}{$list}}; if ($$settings{$id}{$list}{rcardinality} eq 'Single') { @@ -3000,7 +4170,6 @@ sub write_webct4_questions { if ($$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{texttype} eq 'text/html') { $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} = &HTML::Entities::decode($$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text}); $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} = &Apache::loncleanup::htmlclean($$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text}); - $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} =~ s#(= $max) { - $max = $$settings{$id}{strings}{$label}[$k]; - } + } + if ($numerical) { + my $numans; + my $tol; + if (@{$$settings{$id}{strings}{$label}} == 1) { + $tol = '5%'; + $numans = $$settings{$id}{strings}{$label}[0]; + } else { + my $min = $$settings{$id}{strings}{$label}[0]; + my $max = $$settings{$id}{strings}{$label}[0]; + for (my $k=1; $k<@{$$settings{$id}{strings}{$label}}; $k++) { + if ($$settings{$id}{strings}{$label}[$k] <= $min) { + $min = $$settings{$id}{strings}{$label}[$k]; } - $numans = ($max + $min)/2; - if ($numans == 0) { - my $dev = abs($max - $numans); - if (abs($numans - $min) > $dev) { - $dev = abs($numans - $min); - } - $tol = $dev; - } else { - $tol = 100*($max - $min)/($numans*2); - $tol .= '%'; + if ($$settings{$id}{strings}{$label}[$k] >= $max) { + $max = $$settings{$id}{strings}{$label}[$k]; } } - if ($context eq 'CSTR') { - if (@{$$settings{$id}{str}} > 1) { - $output .= qq| -