version 1.16, 2005/03/15 15:25:32
|
version 1.30, 2005/10/25 13:54:46
|
Line 24
|
Line 24
|
package Apache::imsprocessor; |
package Apache::imsprocessor; |
|
|
use Apache::lonnet; |
use Apache::lonnet; |
|
use Apache::loncleanup; |
|
use LWP::UserAgent; |
|
use HTTP::Request::Common; |
use LONCAPA::Configuration; |
use LONCAPA::Configuration; |
use strict; |
use strict; |
|
|
Line 41 sub ims_config {
|
Line 44 sub ims_config {
|
survey => 'assessment/x-bb-survey', |
survey => 'assessment/x-bb-survey', |
users => 'course/x-bb-user', |
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{bb6}{conference} = 'resource/x-bb-conference'; |
%{$$cmsmap{angel}} = ( |
%{$$cmsmap{angel}} = ( |
board => 'BOARD', |
board => 'BOARD', |
Line 95 sub uploadzip {
|
Line 108 sub uploadzip {
|
my ($context,$tempdir,$source) = @_; |
my ($context,$tempdir,$source) = @_; |
my $fname; |
my $fname; |
if ($context eq 'DOCS') { |
if ($context eq 'DOCS') { |
$fname=$ENV{'form.uploadname.filename'}; |
$fname=$env{'form.uploadname.filename'}; |
# Replace Windows backslashes by forward slashes |
# Replace Windows backslashes by forward slashes |
$fname=~s/\\/\//g; |
$fname=~s/\\/\//g; |
# Get rid of everything but the actual filename |
# Get rid of everything but the actual filename |
Line 107 sub uploadzip {
|
Line 120 sub uploadzip {
|
# See if there is anything left |
# See if there is anything left |
unless ($fname) { return 'error: no uploaded file'; } |
unless ($fname) { return 'error: no uploaded file'; } |
# Save the file |
# Save the file |
chomp($ENV{'form.uploadname'}); |
chomp($env{'form.uploadname'}); |
open(my $fh,'>'.$tempdir.'/'.$fname); |
open(my $fh,'>'.$tempdir.'/'.$fname); |
print $fh $ENV{'form.uploadname'}; |
print $fh $env{'form.uploadname'}; |
close($fh); |
close($fh); |
} elsif ($context eq 'CSTR') { |
} elsif ($context eq 'CSTR') { |
if ($source =~ m/\/([^\/]+)$/) { |
if ($source =~ m/\/([^\/]+)$/) { |
Line 128 sub expand_zip {
|
Line 141 sub expand_zip {
|
return 'no zip'; |
return 'no zip'; |
} |
} |
if ($filename =~ m|\.zip$|i) { |
if ($filename =~ m|\.zip$|i) { |
# unzip can cause an sh launch which can pass along all of %ENV |
|
# which can be too large for /bin/sh to handle |
|
my %oldENV=%ENV; |
|
undef(%ENV); |
|
open(OUTPUT, "unzip -o $zipfile -d $tempdir 2> /dev/null |"); |
open(OUTPUT, "unzip -o $zipfile -d $tempdir 2> /dev/null |"); |
close(OUTPUT); |
close(OUTPUT); |
%ENV=%oldENV; |
|
undef(%oldENV); |
|
} else { |
} else { |
return 'nozip'; |
return 'nozip'; |
} |
} |
Line 177 sub process_manifest {
|
Line 184 sub process_manifest {
|
|
|
unless (-e "$tempdir/imsmanifest.xml") { |
unless (-e "$tempdir/imsmanifest.xml") { |
return 'nomanifest'; |
return 'nomanifest'; |
} |
} |
|
|
my $xmlfile = $tempdir.'/imsmanifest.xml'; |
my $xmlfile = $tempdir.'/imsmanifest.xml'; |
my $p = HTML::Parser->new |
my $p = HTML::Parser->new |
Line 187 sub process_manifest {
|
Line 194 sub process_manifest {
|
[sub { |
[sub { |
my ($tagname, $attr) = @_; |
my ($tagname, $attr) = @_; |
push @state, $tagname; |
push @state, $tagname; |
my $num = @state - 3; |
my $start = @state - 3; |
my $start = $num; |
|
my $statestr = ''; |
|
foreach (@state) { |
|
$statestr .= "$_ "; |
|
} |
|
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}) ) { |
my $searchstr = "manifest organizations $toc{$cms}"; |
if ($state[-1] eq 'item') { |
while ($num > 0) { |
|
$searchstr .= " item"; |
|
$num --; |
|
} |
|
if (("@state" eq $searchstr) && (@state > 3)) { |
|
$itm = $attr->{identifier}; |
$itm = $attr->{identifier}; |
if ($$includeditems{$itm} || $phase ne 'build') { |
if ($$includeditems{$itm} || $phase ne 'build') { |
%{$$items{$itm}} = (); |
%{$$items{$itm}} = (); |
Line 260 sub process_manifest {
|
Line 257 sub process_manifest {
|
} |
} |
} |
} |
if ($cms eq 'webct4') { |
if ($cms eq 'webct4') { |
if ("@state" eq "$searchstr webct:properties") { |
if (($state[-1] eq "webct:properties") && (@state > 4)) { |
$$items{$itm}{properties} = $attr->{identifierref}; |
$$items{$itm}{properties} = $attr->{identifierref}; |
} |
} |
} |
} |
Line 392 sub copy_resources {
|
Line 389 sub copy_resources {
|
$copyfile = $1; |
$copyfile = $1; |
} |
} |
} |
} |
unless (($cms eq 'webct4') && ($copyfile eq 'questionDB.xml' || $copyfile =~ m/^quiz_QIZ_\d+\.xml$/)) { |
unless (($cms eq 'webct4') && ($copyfile =~ m/questionDB\.xml$/ || $copyfile =~ m/quiz_QIZ_\d+\.xml$/ || $copyfile =~ m/properties_QIZ_\d+\.xml$/)) { |
$copyfile = $fpath.$copyfile; |
$copyfile = $fpath.$copyfile; |
my $fileresult; |
my $fileresult; |
if (-e $source) { |
if (-e $source) { |
Line 447 sub copy_resources {
|
Line 444 sub copy_resources {
|
if (-e "$tempdir/$file") { |
if (-e "$tempdir/$file") { |
rename("$tempdir/$file","$destdir/resfiles/$copyfile"); |
rename("$tempdir/$file","$destdir/resfiles/$copyfile"); |
} |
} |
} elsif ($file =~ m-/data/(.+)$-) { |
} elsif ($file !~ m-/data/(.+)$-) { |
print STDERR "File $file is a WebCT data file \n"; |
&Apache::lonnet::logthis("IMS import error: WebCT4 - file $file is in unexpected location"); |
} else { |
|
print STDERR "File $file is in unexpected location\n"; |
|
} |
} |
} |
} |
} |
} |
Line 466 sub process_resinfo {
|
Line 461 sub process_resinfo {
|
my $dbparse = 0; |
my $dbparse = 0; |
my $announce_handling = 'include'; |
my $announce_handling = 'include'; |
my $longcrs = ''; |
my $longcrs = ''; |
|
my %qzdbsettings = (); |
|
my %catinfo = (); |
if ($crs =~ m/^(\d)(\d)(\d)/) { |
if ($crs =~ m/^(\d)(\d)(\d)/) { |
$longcrs = $1.'/'.$2.'/'.$3.'/'.$crs; |
$longcrs = $1.'/'.$2.'/'.$3.'/'.$crs; |
} |
} |
Line 527 sub process_resinfo {
|
Line 524 sub process_resinfo {
|
$board_id ++; |
$board_id ++; |
$board_count ++; |
$board_count ++; |
} |
} |
} elsif ($$resources{$key}{type} eq "assessment/x-bb-pool") { |
} elsif ($$resources{$key}{type} =~/assessment\/x\-bb\-(qti\-)?pool/) { |
%{$$resinfo{$key}} = (); |
%{$$resinfo{$key}} = (); |
&process_assessment($cms,$context,$key,$docroot,'pool',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items); |
&process_assessment($cms,$context,$key,$docroot,'pool',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs); |
push @{$pools}, $key; |
push @{$pools}, $key; |
} elsif ($$resources{$key}{type} eq "assessment/x-bb-quiz") { |
} elsif ($$resources{$key}{type} =~ /assessment\/x\-bb\-(qti\-)?quiz/) { |
%{$$resinfo{$key}} = (); |
%{$$resinfo{$key}} = (); |
&process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items); |
&process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs); |
push @{$quizzes}, $key; |
push @{$quizzes}, $key; |
} elsif ($$resources{$key}{type} eq "assessment/x-bb-survey") { |
} elsif ($$resources{$key}{type} =~ /assessment\/x\-bb\-(qti\-)?survey/) { |
%{$$resinfo{$key}} = (); |
%{$$resinfo{$key}} = (); |
&process_assessment($cms,$context,$key,$docroot,'survey',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items); |
&process_assessment($cms,$context,$key,$docroot,'survey',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs); |
push @{$surveys}, $key; |
push @{$surveys}, $key; |
} elsif ($$resources{$key}{type} eq "assessment/x-bb-group") { |
} elsif ($$resources{$key}{type} eq "assessment/x-bb-group") { |
%{$$resinfo{$key}} = (); |
%{$$resinfo{$key}} = (); |
Line 579 sub process_resinfo {
|
Line 576 sub process_resinfo {
|
%{$$resinfo{$key}} = (); |
%{$$resinfo{$key}} = (); |
&webct4_content($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$$resources{$key}{type},$$items{$$resources{$key}{revitm}}{title},$resrcfiles); |
&webct4_content($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$$resources{$key}{type},$$items{$$resources{$key}{revitm}}{title},$resrcfiles); |
} elsif ($$resources{$key}{type} eq "webctquiz") { |
} elsif ($$resources{$key}{type} eq "webctquiz") { |
# &webct4_assessment($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$$resources{$key}{type},$$items{$$resources{$key}{revitm}}{title},$resrcfiles); |
&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); |
|
} |
} |
} |
} |
} |
} |
Line 670 sub build_structure {
|
Line 666 sub build_structure {
|
<resource id="$next_id" src="" type="finish"></resource>\n|; |
<resource id="$next_id" src="" type="finish"></resource>\n|; |
} |
} |
} else { |
} else { |
print "key is $key\n"; |
|
my $contcount = 0; |
my $contcount = 0; |
if (defined($$items{$key}{contents})) { |
if (defined($$items{$key}{contents})) { |
$contcount = @{$$items{$key}{contents}}; |
$contcount = @{$$items{$key}{contents}}; |
} else { |
} else { |
print STDERR "not defined for $key\n"; |
&Apache::lonnet::logthis("IMS Import error for item: $key- contents count = $contentscount, but identity of contents not defined."); |
} |
} |
my $contitem = $$items{$key}{contents}[0]; |
my $contitem = $$items{$key}{contents}[0]; |
my $contitemcount = $$items{$contitem}{contentscount}; |
my $contitemcount = $$items{$contitem}{contentscount}; |
Line 691 sub build_structure {
|
Line 686 sub build_structure {
|
if (grep/^$res$/,@{$packages}) { |
if (grep/^$res$/,@{$packages}) { |
$packageflag = 1; |
$packageflag = 1; |
} |
} |
$src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount); |
$src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem}); |
unless ($flag{$key}{page} == 1) { |
unless ($flag{$key}{page} == 1) { |
|
if ($$randompicks{$contitem}) { |
|
$seqtext{$key} .= qq| |
|
<param to="$curr_id" type="int_pos" name="parameter_randompick" value="$$randompicks{$contitem}"></param>\n|; |
|
} |
$seqtext{$key} .= qq|<resource id="$curr_id" src="$src" title="$title" type="start"|; |
$seqtext{$key} .= qq|<resource id="$curr_id" src="$src" title="$title" type="start"|; |
unless ($flag{$key}{seq} || $flag{$key}{board} || $flag{$key}{file}) { |
unless ($flag{$key}{seq} || $flag{$key}{board} || $flag{$key}{file}) { |
$flag{$key}{page} = 1; |
$flag{$key}{page} = 1; |
Line 727 sub build_structure {
|
Line 726 sub build_structure {
|
if (grep/^$res$/,@{$packages}) { |
if (grep/^$res$/,@{$packages}) { |
$packageflag = 1; |
$packageflag = 1; |
} |
} |
$src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount); |
$src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem}); |
|
|
unless ($flag{$key}{page} == 1) { |
unless ($flag{$key}{page} == 1) { |
$seqtext{$key} .= qq|></resource> |
$seqtext{$key} .= qq|></resource> |
<link from="$curr_id" to="$next_id" index="$curr_id"></link> |
<link from="$curr_id" to="$next_id" index="$curr_id"></link>\n|; |
|
if ($$randompicks{$contitem}) { |
|
$seqtext{$key} .= qq| |
|
<param to="$next_id" type="int_pos" name="parameter_randompick" value="$$randompicks{$contitem}"></param>|; |
|
} |
|
$seqtext{$key} .= qq| |
<resource id="$next_id" src="$src" title="$title"|; |
<resource id="$next_id" src="$src" title="$title"|; |
$curr_id ++; |
$curr_id ++; |
$next_id ++; |
$next_id ++; |
Line 755 sub build_structure {
|
Line 758 sub build_structure {
|
if (grep/^$res$/,@{$packages}) { |
if (grep/^$res$/,@{$packages}) { |
$packageflag = 1; |
$packageflag = 1; |
} |
} |
$src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount); |
$src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem}); |
|
|
if ($flag{$key}{page}) { |
if ($flag{$key}{page}) { |
if ($count{$key}{seq} + $count{$key}{page} + $count{$key}{board} + $count{$key}{file} +1 == 1) { |
if ($count{$key}{seq} + $count{$key}{page} + $count{$key}{board} + $count{$key}{file} +1 == 1) { |
Line 765 sub build_structure {
|
Line 768 sub build_structure {
|
} |
} |
} else { |
} else { |
$seqtext{$key} .= qq|></resource> |
$seqtext{$key} .= qq|></resource> |
<link from="$curr_id" to="$next_id" index="$curr_id"></link> |
<link from="$curr_id" to="$next_id" index="$curr_id"></link>\n|; |
|
if ($$randompicks{$contitem}) { |
|
$seqtext{$key} .= qq| |
|
<param to="$next_id" type="int_pos" name="parameter_randompick" value="$$randompicks{$contitem}"></param>\n|; |
|
} |
|
$seqtext{$key} .= qq| |
<resource id="$next_id" src="$src" title="$title" |; |
<resource id="$next_id" src="$src" title="$title" |; |
if ($key eq 'Top') { |
if ($key eq 'Top') { |
push @{$topurls}, $src; |
push @{$topurls}, $src; |
Line 877 sub build_structure {
|
Line 885 sub build_structure {
|
} |
} |
|
|
sub make_structure { |
sub make_structure { |
my ($cms,$key,$srcstem,$flag,$count,$timestamp,$boardnum,$hrefs,$pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount) = @_; |
my ($cms,$key,$srcstem,$flag,$count,$timestamp,$boardnum,$hrefs,$pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$randompick) = @_; |
my $src =''; |
my $src =''; |
if (($cms eq 'angel' && $type eq 'FOLDER') || (($cms eq 'bb5' || $cms eq 'bb6') && (($$resinfo{$res}{'isfolder'} eq 'true') || $key eq 'Top')) || ($cms eq 'webct4' && $contitemcount > 0)) { |
if (($cms eq 'angel' && $type eq 'FOLDER') || (($cms eq 'bb5' || $cms eq 'bb6') && (($$resinfo{$res}{'isfolder'} eq 'true') || $key eq 'Top')) || ($cms eq 'webct4' && $contitemcount > 0)) { |
$src = $srcstem.'/sequences/'.$contitem.'.sequence'; |
$src = $srcstem.'/sequences/'.$contitem.'.sequence'; |
$$flag{$key}{page} = 0; |
$$flag{$key}{page} = 0; |
$$flag{$key}{seq} = 1; |
$$flag{$key}{seq} = 1; |
$$count{$key}{seq} ++; |
$$count{$key}{seq} ++; |
|
} elsif ($cms eq 'webct4' && $randompick) { |
|
$src = $srcstem.'/sequences/'.$res.'.sequence'; |
|
$$flag{$key}{page} = 0; |
|
$$flag{$key}{seq} = 1; |
|
$$count{$key}{seq} ++; |
} elsif ($cms eq 'angel' && $type eq 'BOARD') { |
} elsif ($cms eq 'angel' && $type eq 'BOARD') { |
$src = '/adm/'.$cdom.'/'.$uname.'/'.$$timestamp[$$boardnum{$res}].'/bulletinboard'; |
$src = '/adm/'.$cdom.'/'.$uname.'/'.$$timestamp[$$boardnum{$res}].'/bulletinboard'; |
$$flag{$key}{page} = 0; |
$$flag{$key}{page} = 0; |
Line 900 sub make_structure {
|
Line 913 sub make_structure {
|
} elsif ($cms eq 'angel' && (($type eq "PAGE") || ($type eq "LINK")) ) { |
} elsif ($cms eq 'angel' && (($type eq "PAGE") || ($type eq "LINK")) ) { |
if ($$flag{$key}{page}) { |
if ($$flag{$key}{page}) { |
if ($$count{$key}{page} == -1) { |
if ($$count{$key}{page} == -1) { |
print STDERR "Array index is -1, we shouldnt be here, key is $key, type is $type\n"; |
&Apache::lonnet::logthis("IMS Angel import error in array index for page: value = -1, resource is $key, type is $type."); |
} else { |
} else { |
push @{$$pagecontents{$key}[$$count{$key}{page}]},$contitem; |
push @{$$pagecontents{$key}[$$count{$key}{page}]},$contitem; |
} |
} |
Line 928 sub make_structure {
|
Line 941 sub make_structure {
|
$$flag{$key}{seq} = 0; |
$$flag{$key}{seq} = 0; |
} |
} |
} elsif ($cms eq 'webct4') { |
} elsif ($cms eq 'webct4') { |
unless ($type eq 'webctquiz') { |
if ($type eq 'webctquiz') { |
|
$src = $srcstem.'/pages/'.$res.'.page'; |
|
$$count{$key}{page} ++; |
|
$$flag{$key}{seq} = 0; |
|
} else { |
if (grep/^$file$/,@{$$hrefs{$res}}) { |
if (grep/^$file$/,@{$$hrefs{$res}}) { |
my $filename; |
my $filename; |
if ($file =~ m-/([^/]+)$-) { |
if ($file =~ m-/([^/]+)$-) { |
Line 1720 sub parse_bb5_assessment {
|
Line 1737 sub parse_bb5_assessment {
|
$id = $attr->{id}; |
$id = $attr->{id}; |
} elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "BODY") && ($state[3] eq "FLAGS") ) { |
} elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "BODY") && ($state[3] eq "FLAGS") ) { |
if ($state[4] eq "ISHTML") { |
if ($state[4] eq "ISHTML") { |
$$settings{$id}{html} = $attr->{value}; |
$$settings{$id}{ishtml} = $attr->{value}; |
} elsif ($state[4] eq "ISNEWLINELITERAL") { |
} elsif ($state[4] eq "ISNEWLINELITERAL") { |
$$settings{$id}{newline} = $attr->{value}; |
$$settings{$id}{newline} = $attr->{value}; |
} |
} |
Line 1820 sub parse_bb5_assessment {
|
Line 1837 sub parse_bb5_assessment {
|
} |
} |
|
|
sub parse_bb6_assessment { |
sub parse_bb6_assessment { |
my ($res,$docroot,$container,$settings,$allanswers,$allchoices,$allids) = @_; |
my ($res,$docroot,$container,$settings,$allids) = @_; |
return; |
my $xmlfile = $docroot.'/'.$res.".dat"; |
|
my @state = (); |
|
my $id; # the current question ID |
|
my $response; # the current response ID |
|
my $foil; # the current foil ID |
|
my $numchoice; # the current right match choice; |
|
my $labelcount; # the current count of choices for a matching item. |
|
my $curr_shuffle; |
|
my $curr_class; # the current question type |
|
my $curr_matchitem; |
|
my $curr_block_type; # the current block type |
|
my $curr_flow; # the current flow class attribute |
|
my $curr_flow_mat; # the current flow_mat class attribute |
|
my $curr_feedback_type; # the current feedback type |
|
my $numorder; # counter for ordering type questions |
|
|
|
my $itemfrag = "questestinterop assessment section item"; |
|
my $presfrag = "$itemfrag presentation flow flow"; |
|
my $blockflow = 'flow'; |
|
my $responselid; |
|
my $instructionfrag = "questestinterop assessment presentation_material flow_mat material"; |
|
my $feedbackfrag = "$itemfrag itemfeedback"; |
|
my $feedback_tag = ''; |
|
my $responselid; |
|
my $p = HTML::Parser->new |
|
( |
|
xml_mode => 1, |
|
start_h => |
|
[sub { |
|
my ($tagname, $attr) = @_; |
|
push @state, $tagname; |
|
if ("@state" eq "questestinterop assessment") { |
|
$$settings{title} = $attr->{title}; |
|
} |
|
if ("@state" eq "questestinterop assessment rubric flow_mat material mat_extension mat_formattedtext") { |
|
$$settings{description}{texttype} = $attr->{type}; |
|
} |
|
if ("@state" eq $presfrag) { |
|
if ($attr->{class} eq 'QUESTION_BLOCK') { |
|
$curr_block_type = 'question'; |
|
} elsif ($attr->{class} eq 'RESPONSE_BLOCK') { |
|
$curr_block_type = 'response'; |
|
if ($curr_class eq 'Matching') { |
|
$responselid = 'flow response_lid'; |
|
} else { |
|
$responselid = 'response_lid'; |
|
} |
|
} elsif (($attr->{class} eq 'RIGHT_MATCH_BLOCK')) { |
|
$numchoice = 0; |
|
$curr_block_type = 'rightmatch'; |
|
} |
|
} |
|
if ("@state" eq "$presfrag flow") { |
|
if (($curr_block_type =~ /^rightmatch/) && ($attr->{class} eq 'Block')) { |
|
$curr_block_type = 'rightmatch'.$numchoice; |
|
$numchoice ++; |
|
} |
|
} |
|
if ($state[-1] eq 'flow') { |
|
$curr_flow = $attr->{class}; |
|
} |
|
if ($state[-1] eq 'flow_mat') { |
|
$curr_flow_mat = $attr->{class}; |
|
} |
|
if ("@state" eq "$presfrag $blockflow material mat_extension mat_formattedtext") { |
|
$$settings{$id}{$curr_block_type}{texttype} = $attr->{texttype}; |
|
} |
|
if ("@state" eq "$presfrag $blockflow material matapplication") { |
|
$$settings{$id}{$curr_block_type}{image} = $attr->{uri}; |
|
$$settings{$id}{$curr_block_type}{style} = $attr->{embedded}; |
|
$$settings{$id}{$curr_block_type}{label} = $attr->{label}; |
|
} |
|
if ("@state" eq "$presfrag $blockflow material mattext") { |
|
$$settings{$id}{$curr_block_type}{link} = $attr->{uri}; |
|
} |
|
if ("@state" eq "$presfrag $responselid") { |
|
$response = $attr->{ident}; |
|
$labelcount = 0; |
|
if ($curr_class eq 'Matching') { |
|
push(@{$$settings{$id}{answers}},$response); |
|
%{$$settings{$id}{$response}} = (); |
|
foreach my $key (keys(%{$$settings{$id}{$curr_block_type}})) { |
|
$$settings{$id}{$response}{$key} = $$settings{$id}{$curr_block_type}{$key}; |
|
} |
|
%{$$settings{$id}{$curr_block_type}} = (); |
|
} |
|
} |
|
if ("@state" eq "$presfrag $responselid render_choice") { |
|
$curr_shuffle = $attr->{shuffle}; |
|
} |
|
if ("@state" eq "$presfrag $responselid render_choice flow_label response_label") { |
|
$foil = $attr->{ident}; |
|
%{$$settings{$id}{$foil}} = (); |
|
$$settings{$id}{$foil}{randomize} = $curr_shuffle; |
|
unless ($curr_class eq 'Essay'){ |
|
if ($curr_class eq 'Matching') { |
|
push(@{$$settings{$id}{$response}{items}},$foil); |
|
$$settings{$id}{$foil}{order} = $labelcount; |
|
$labelcount ++; |
|
} else { |
|
push(@{$$settings{$id}{answers}},$foil); |
|
@{$$settings{$id}{correctanswer}} = (); |
|
} |
|
} |
|
} |
|
if ("@state" eq "$presfrag $responselid render_choice flow_label response_label flow_mat material matapplication") { |
|
$$settings{$id}{$foil}{filetype} = $attr->{embedded}; |
|
$$settings{$id}{$foil}{label} = $attr->{label}; |
|
$$settings{$id}{$foil}{uri} = $attr->{uri}; |
|
} |
|
if ("@state" eq "$presfrag $responselid render_choice flow_label response_label flow_mat material mattext") { |
|
$$settings{$id}{$foil}{link} = $attr->{uri}; |
|
} |
|
if ("@state" eq "questestinterop assessment section item resprocessing") { |
|
if ($curr_class eq 'Matching') { |
|
$$settings{$id}{allchoices} = $numchoice; |
|
} |
|
} |
|
if ("@state" eq "questestinterop assessment section item resprocessing respcondition conditionvar varequal") { |
|
if ($curr_class eq 'Matching') { |
|
$curr_matchitem = $attr->{respident}; |
|
} |
|
} |
|
if ("@state" eq $feedbackfrag) { |
|
$curr_feedback_type = $attr->{ident}; |
|
$feedback_tag = ""; |
|
} |
|
if ("@state" eq "$feedbackfrag solution") { |
|
$curr_feedback_type = 'solution'; |
|
$feedback_tag = "solution solutionmaterial"; |
|
} |
|
if ("@state" eq "$feedbackfrag $feedback_tag flow_mat flow_mat material matapplication") { |
|
$$settings{$id}{$curr_feedback_type.'feedback'}{filetype} = $attr->{'embedded'}; |
|
$$settings{$id}{$curr_feedback_type.'feedback'}{label} = $attr->{label}; |
|
$$settings{$id}{$curr_feedback_type.'feedback'}{uri} = $attr->{uri}; |
|
} |
|
if ("@state" eq "$feedbackfrag $feedback_tag flow_mat flow_mat material mattext") { |
|
$$settings{$id}{$curr_feedback_type.'feedback'}{link} = $attr->{uri}; |
|
} |
|
}, "tagname, attr"], |
|
text_h => |
|
[sub { |
|
my ($text) = @_; |
|
$text =~ s/^\s+//g; |
|
$text =~ s/\s+$//g; |
|
if ("@state" eq "questestinterop assessment rubric flow_mat material mat_extension mat_formattedtext") { |
|
$$settings{description}{text} = $text; |
|
} |
|
if ("@state" eq "questestinterop assessment rubric flow_mat material mattext") { |
|
$$settings{description}{text} = $text; |
|
} |
|
if ("@state" eq "$instructionfrag mat_extension mat_formattedtext") { |
|
$$settings{instructions}{text} = $text; |
|
} |
|
if ("@state" eq "$instructionfrag mattext") { |
|
$$settings{instructions}{text} = $text; |
|
} |
|
if ("@state" eq "questestinterop assessment section item itemmetadata bbmd_asi_object_id") { |
|
$id = $text; |
|
push @{$allids}, $id; |
|
%{$$settings{$id}} = (); |
|
@{$$settings{$id}{answers}} = (); |
|
%{$$settings{$id}{question}} = (); |
|
%{$$settings{$id}{correctfeedback}} = (); |
|
%{$$settings{$id}{incorrectfeedback}} = (); |
|
%{$$settings{$id}{solutionfeedback}} = (); |
|
} |
|
if ("@state" eq "questestinterop assessment section item itemmetadata bbmd_questiontype") { |
|
$$settings{$id}{class} = $text; |
|
$curr_class = $text; |
|
if ($curr_class eq 'Matching') { |
|
$blockflow = 'flow flow'; |
|
} else { |
|
$blockflow = 'flow'; |
|
} |
|
} |
|
if ("@state" eq "$presfrag $blockflow material mat_extension mat_formattedtext") { |
|
$$settings{$id}{$curr_block_type}{text} = $text; |
|
} |
|
if ("@state" eq "$presfrag $blockflow material mattext") { |
|
if ($curr_flow eq 'LINK_BLOCK') { |
|
$$settings{$id}{$curr_block_type}{linkname} = $text; |
|
} elsif ($curr_flow eq 'FORMATTED_TEXT_BLOCK') { |
|
$$settings{$id}{$curr_block_type}{text} = $text; |
|
} |
|
} |
|
if ("@state" eq "$presfrag $responselid render_choice flow_label response_label flow_mat material mat_extension mat_formattedtext") { |
|
$$settings{$id}{$foil}{text} = $text; |
|
} |
|
if ("@state" eq "$presfrag $responselid render_choice flow_label response_label flow_mat material mattext") { |
|
if ($curr_flow_mat eq 'LINK_BLOCK') { |
|
$$settings{$id}{$foil}{linkname} = $text; |
|
} else { |
|
$$settings{$id}{$foil}{text} = $text; |
|
} |
|
} |
|
if ("@state" eq "questestinterop assessment section item resprocessing respcondition conditionvar varequal") { |
|
if ($curr_class eq 'Matching') { |
|
$$settings{$id}{$curr_matchitem}{correctanswer} = $text; |
|
} else { |
|
push(@{$$settings{$id}{correctanswer}},$text); |
|
} |
|
} |
|
if ("@state" eq "questestinterop assessment section item resprocessing respcondition conditionvar") { |
|
$numorder = 0; |
|
} |
|
if ("@state" eq "questestinterop assessment section item resprocessing respcondition conditionvar and varequal") { |
|
push(@{$$settings{$id}{correctanswer}},$text); |
|
if ($curr_class eq 'Ordering') { |
|
$numorder ++; |
|
$$settings{$id}{$text}{order} = $numorder; |
|
} |
|
} |
|
if ("@state" eq "$feedbackfrag $feedback_tag flow_mat flow_mat material mat_extension mat_formattedtext") { |
|
$$settings{$id}{$curr_feedback_type.'feedback'}{text} = $text; |
|
} |
|
if ("@state" eq "$feedbackfrag $feedback_tag flow_mat flow_mat material mattext") { |
|
$$settings{$id}{$curr_feedback_type.'feedback'}{linkname} = $text; |
|
} |
|
}, "dtext"], |
|
end_h => |
|
[sub { |
|
my ($tagname) = @_; |
|
pop @state; |
|
}, "tagname"], |
|
); |
|
$p->unbroken_text(1); |
|
$p->marked_sections(1); |
|
$p->parse_file($xmlfile); |
|
$p->eof; |
|
return; |
} |
} |
|
|
sub parse_webct4_assessment { |
sub parse_webct4_assessment { |
my ($res,$docroot,$href,$container,$allids) = @_; |
my ($res,$docroot,$href,$container,$allids) = @_; |
my $xmlfile = $docroot.'/'.$href; #quiz file |
my $xmlfile = $docroot.'/'.$href; #quiz file |
print STDERR "quiz file -- XML file is $xmlfile\n"; |
|
my @state = (); |
my @state = (); |
my $id; # the current question ID |
my $id; # the current question ID |
my $p = HTML::Parser->new |
my $p = HTML::Parser->new |
Line 1862 sub parse_webct4_assessment {
|
Line 2108 sub parse_webct4_assessment {
|
sub parse_webct4_quizprops { |
sub parse_webct4_quizprops { |
my ($res,$docroot,$href,$container,$qzparams) = @_; |
my ($res,$docroot,$href,$container,$qzparams) = @_; |
my $xmlfile = $docroot.'/'.$href; #properties file |
my $xmlfile = $docroot.'/'.$href; #properties file |
print STDERR "props file -- XML file is $xmlfile\n"; |
|
my @state = (); |
my @state = (); |
%{$$qzparams{$res}} = (); |
%{$$qzparams{$res}} = (); |
my $p = HTML::Parser->new |
my $p = HTML::Parser->new |
Line 1872 sub parse_webct4_quizprops {
|
Line 2117 sub parse_webct4_quizprops {
|
[sub { |
[sub { |
my ($tagname, $attr) = @_; |
my ($tagname, $attr) = @_; |
push @state, $tagname; |
push @state, $tagname; |
my $depth = 0; |
|
my @seq = (); |
|
if ($state[0] eq 'properties' && $state[1] eq 'processing') { |
|
if ($state[2] eq 'scores' && $state[3] eq 'score') { |
|
$$qzparams{$res}{weight} = $attr->{linkrefid}; |
|
} elsif ($state[2] eq 'selection' && $state[3] eq 'select') { |
|
$$qzparams{$res}{numpick} = $attr->{linkrefid}; |
|
} |
|
} |
|
}, "tagname, attr"], |
}, "tagname, attr"], |
text_h => |
text_h => |
[sub { |
[sub { |
Line 1889 sub parse_webct4_quizprops {
|
Line 2125 sub parse_webct4_quizprops {
|
if ($state[2] eq 'time_available') { |
if ($state[2] eq 'time_available') { |
$$qzparams{$res}{opendate} = $text; |
$$qzparams{$res}{opendate} = $text; |
} elsif ($state[2] eq 'time_due') { |
} elsif ($state[2] eq 'time_due') { |
$$qzparams{$res}{opendate} = $text; |
$$qzparams{$res}{duedate} = $text; |
} elsif ($state[3] eq 'max_attempt') { |
} elsif ($state[3] eq 'max_attempt') { |
$$qzparams{$res}{tries} = $text; |
$$qzparams{$res}{tries} = $text; |
} elsif ($state[3] eq 'post_submission') { |
} elsif ($state[3] eq 'post_submission') { |
$$qzparams{$res}{posts} = $text; |
$$qzparams{$res}{posts} = $text; |
|
} elsif ($state[3] eq 'method') { |
|
$$qzparams{$res}{method} = $text; |
|
} |
|
} elsif ($state[0] eq 'properties' && $state[1] eq 'processing') { |
|
if ($state[2] eq 'scores' && $state[3] eq 'score') { |
|
$$qzparams{$res}{weight} = $text; |
|
} elsif ($state[2] eq 'selection' && $state[3] eq 'select') { |
|
$$qzparams{$res}{numpick} = $text; |
} |
} |
} elsif ($state[0] eq 'properties' && $state[1] eq 'result') { |
} elsif ($state[0] eq 'properties' && $state[1] eq 'result') { |
if ($state[2] eq 'display_answer') { |
if ($state[2] eq 'display_answer') { |
$$qzparams{$res}{answerdate} = $text; |
$$qzparams{$res}{showanswer} = $text; |
} |
} |
} |
} |
}, "dtext"], |
}, "dtext"], |
Line 2091 sub parse_webct4_questionDB {
|
Line 2335 sub parse_webct4_questionDB {
|
$$settings{$id}{$numid}{toltype} = $attr->{type}; |
$$settings{$id}{$numid}{toltype} = $attr->{type}; |
} |
} |
if ("@state" eq "questestinterop section item resprocessing itemproc_extension webct:x_webct_v01_autocalculate webct:x_webct_v01_unit") { |
if ("@state" eq "questestinterop section item resprocessing itemproc_extension webct:x_webct_v01_autocalculate webct:x_webct_v01_unit") { |
my $unitid = $attr->{ident}; |
$unitid = $attr->{ident}; |
%{$$settings{$id}{$numid}{$unitid}} = (); |
%{$$settings{$id}{$numid}{$unitid}} = (); |
push(@{$$settings{$id}{$numid}{units}},$unitid); |
push(@{$$settings{$id}{$numid}{units}},$unitid); |
$$settings{$id}{$numid}{$unitid}{value} = $attr->{value}; |
$$settings{$id}{$numid}{$unitid}{value} = $attr->{value}; |
Line 2269 sub parse_webct4_questionDB {
|
Line 2513 sub parse_webct4_questionDB {
|
} |
} |
|
|
sub process_assessment { |
sub process_assessment { |
my ($cms,$context,$res,$docroot,$container,$dirname,$destdir,$settings,$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,$dbparse,$resources,$items) = @_; |
my ($cms,$context,$res,$docroot,$container,$dirname,$destdir,$settings,$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,$dbparse,$resources,$items,$catinfo,$qzdbsettings,$hrefs) = @_; |
my @allids = (); |
my @allids = (); |
my %allanswers = (); |
my %allanswers = (); |
my %allchoices = (); |
my %allchoices = (); |
my %qzparams = (); |
my %qzparams = (); |
my @allquestids = (); |
my @allquestids = (); |
my %catinfo = (); |
|
my %qzdbsettings = (); |
|
my %alldbanswers = (); |
my %alldbanswers = (); |
my %alldbchoices = (); |
my %alldbchoices = (); |
my @alldbquestids = (); |
my @alldbquestids = (); |
Line 2285 sub process_assessment {
|
Line 2527 sub process_assessment {
|
my $randompickflag = 0; |
my $randompickflag = 0; |
my ($cid,$cdom,$cnum); |
my ($cid,$cdom,$cnum); |
if ($context eq 'DOCS') { |
if ($context eq 'DOCS') { |
$cid = $ENV{'request.course.id'}; |
$cid = $env{'request.course.id'}; |
($cdom,$cnum) = split/_/,$cid; |
($cdom,$cnum) = split/_/,$cid; |
} |
} |
my $destresdir = $destdir; |
my $destresdir = $destdir; |
Line 2297 sub process_assessment {
|
Line 2539 sub process_assessment {
|
if ($cms eq 'bb5') { |
if ($cms eq 'bb5') { |
&parse_bb5_assessment($res,$docroot,$container,$settings,\%allanswers,\%allchoices,\@allids); |
&parse_bb5_assessment($res,$docroot,$container,$settings,\%allanswers,\%allchoices,\@allids); |
} elsif ($cms eq 'bb6') { |
} elsif ($cms eq 'bb6') { |
&parse_bb6_assessment($res,$docroot,$container,$settings,\%allanswers,\%allchoices,\@allids); |
&parse_bb6_assessment($res,$docroot,$container,$settings,\@allids); |
} elsif ($cms eq 'webct4') { |
} elsif ($cms eq 'webct4') { |
unless($$dbparse) { |
unless($$dbparse) { |
&parse_webct4_questionDB($docroot,$$resources{$res}{file},\%catinfo,\%qzdbsettings,\%alldbanswers,\%alldbchoices,\@alldbquestids); |
&parse_webct4_questionDB($docroot,$$resources{$res}{file},$catinfo,$qzdbsettings,\%alldbanswers,\%alldbchoices,\@alldbquestids); |
if (!-e "$destdir/sequences") { |
if (!-e "$destdir/sequences") { |
mkdir("$destdir/sequences",0755); |
mkdir("$destdir/sequences",0755); |
} |
} |
my $numcats = scalar(keys %catinfo); |
my $numcats = scalar(keys %{$catinfo}); |
my $curr_id = 0; |
my $curr_id = 0; |
my $next_id = 1; |
my $next_id = 1; |
my $fh; |
my $fh; |
open($fh,">$destdir/sequences/question_database.sequence"); |
open($fh,">$destdir/sequences/question_database.sequence"); |
push @{$sequencesfiles},'question_database.sequence'; |
push @{$sequencesfiles},'question_database.sequence'; |
foreach my $category (sort keys %catinfo) { |
foreach my $category (sort keys %{$catinfo}) { |
my $seqname = $catinfo{$category}{title}.'_'.$category; |
my $seqname = $$catinfo{$category}{title}.'_'.$category; |
$seqname =~ s/\s/_/g; |
$seqname =~ s/\s/_/g; |
$seqname =~ s/\W//g; |
$seqname =~ s/\W//g; |
push(@{$sequencesfiles},$seqname.'.sequence'); |
push(@{$sequencesfiles},$seqname.'.sequence'); |
my $catsrc = "$destresdir/sequences/$seqname.sequence"; |
my $catsrc = "$destresdir/sequences/$seqname.sequence"; |
if ($curr_id == 0) { |
if ($curr_id == 0) { |
print $fh qq|<resource id="1" src="$catsrc" type="start" title="$catinfo{$category}{title}"></resource>|; |
print $fh qq|<resource id="1" src="$catsrc" type="start" title="$$catinfo{$category}{title}"></resource>|; |
} |
} |
if ($numcats == 1) { |
if ($numcats == 1) { |
print $fh qq| |
print $fh qq| |
Line 2329 sub process_assessment {
|
Line 2571 sub process_assessment {
|
$catsrc = "$destresdir/sequences/$seqname.sequence"; |
$catsrc = "$destresdir/sequences/$seqname.sequence"; |
print $fh qq| |
print $fh qq| |
<link from="$curr_id" to="$next_id" index="$curr_id"></link> |
<link from="$curr_id" to="$next_id" index="$curr_id"></link> |
<resource id="$next_id" src="$catsrc" title="$catinfo{$category}{title}"|; |
<resource id="$next_id" src="$catsrc" title="$$catinfo{$category}{title}"|; |
if ($next_id == $numcats) { |
if ($next_id == $numcats) { |
print $fh qq| type="finish"></resource>\n|; |
print $fh qq| type="finish"></resource>\n|; |
} else { |
} else { |
Line 2343 sub process_assessment {
|
Line 2585 sub process_assessment {
|
if (!-e "$destdir/problems/$seqname") { |
if (!-e "$destdir/problems/$seqname") { |
mkdir("$destdir/problems/$seqname",0755); |
mkdir("$destdir/problems/$seqname",0755); |
} |
} |
my $newdir = "$destdir/problems/$seqname"; |
$newdir = "$destdir/problems/$seqname"; |
my $dbcontainerdir; |
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); |
&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); |
close($fh); |
&write_webct4_questions(\@alldbquestids,$context,\%qzdbsettings,$dirname,\%alldbanswers,\%alldbchoices,$total,$cid,$cdom,$cnum,$destdir,\%catinfo); |
&write_webct4_questions(\@alldbquestids,$context,$qzdbsettings,$dirname,\%alldbanswers,\%alldbchoices,$total,$cid,$cdom,$cnum,$destdir,$catinfo); |
$$dbparse = 1; |
$$dbparse = 1; |
} |
} |
&parse_webct4_assessment($res,$docroot,$$resources{$res}{file},$container,\@allids); |
&parse_webct4_assessment($res,$docroot,$$resources{$res}{file},$container,\@allids); |
&parse_webct4_quizprops($res,$docroot,$$resources{$$items{$$resources{$res}{revitm}}{properties}}{file},$container,\%qzparams); |
&parse_webct4_quizprops($res,$docroot,$$hrefs{$$items{$$resources{$res}{revitm}}{properties}}[0],$container,\%qzparams); |
foreach (sort keys %qzparams) { |
if (exists($qzparams{$res}{numpick})) { |
if (exists($qzparams{$res}{numpick})) { |
if ($qzparams{$res}{numpick} < @allids) { |
if ($qzparams{$res}{numpick} < @allids) { |
$$randompicks{$$resources{$res}{revitm}} = $qzparams{$res}{numpick}; |
$$randompicks{$res} = $qzparams{$res}{numpick}; |
$randompickflag = 1; |
$randompickflag = 1; |
|
} |
|
} |
} |
} |
} |
} |
} |
Line 2373 sub process_assessment {
|
Line 2613 sub process_assessment {
|
if (!-e "$destdir/problems/$dirtitle") { |
if (!-e "$destdir/problems/$dirtitle") { |
mkdir("$destdir/problems/$dirtitle",0755); |
mkdir("$destdir/problems/$dirtitle",0755); |
} |
} |
my $newdir = "$destdir/problems/$dirtitle"; |
$newdir = "$destdir/problems/$dirtitle"; |
} |
} |
|
|
&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 'webct4') { |
|
&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); |
|
} |
if ($cms eq 'bb5') { |
if ($cms eq 'bb5') { |
&write_bb5_questions(\@allids,$containerdir,$context,$settings,$dirname,$res,\%allanswers,\%allchoices,$total,$newdir,$cid,$cdom,$cnum); |
&write_bb5_questions(\@allids,$containerdir,$context,$settings,$dirname,$destdir,$res,\%allanswers,\%allchoices,$total,$newdir,$cid,$cdom,$cnum,$docroot); |
} elsif ($cms eq 'bb6') { |
} elsif ($cms eq 'bb6') { |
&write_bb6_questions(\@allids,$containerdir,$context,$settings,$dirname,$res,\%allanswers,\%allchoices,$total,$newdir,$cid,$cdom,$cnum); |
&write_bb6_questions(\@allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$total,$newdir,$cid,$cdom,$cnum,$docroot); |
} |
} |
} |
} |
|
|
Line 2410 sub build_problem_container {
|
Line 2654 sub build_problem_container {
|
} |
} |
print $fh qq|<map> |
print $fh qq|<map> |
|; |
|; |
|
my %probtitle = (); |
my $probsrc = "/res/lib/templates/simpleproblem.problem"; |
my $probsrc = "/res/lib/templates/simpleproblem.problem"; |
if ($context eq 'CSTR') { |
if ($context eq 'CSTR') { |
|
foreach my $id (@{$allids}) { |
|
if ($cms eq 'webct4') { |
|
$probtitle{$id} = $$settings{$id}{title}; |
|
} else { |
|
$probtitle{$id} = $$settings{title}; |
|
} |
|
$probtitle{$id} =~ s/\s/_/g; |
|
$probtitle{$id} =~ s/\W//g; |
|
$probtitle{$id} .= '_'.$id; |
|
} |
if ($cms eq 'webct4' && $container ne 'database') { |
if ($cms eq 'webct4' && $container ne 'database') { |
my $catid = $$settings{$$allids[0]}{category}; |
my $catid = $$settings{$$allids[0]}{category}; |
my $probdir = $$catinfo{$catid}{title}.'_'.$catid; |
my $probdir = $$catinfo{$catid}{title}.'_'.$catid; |
$probdir =~ s/\s/_/g; |
$probdir =~ s/\s/_/g; |
$probdir =~ s/\W//g; |
$probdir =~ s/\W//g; |
$probsrc = "$dirname/problems/$probdir/$$allids[0].problem"; |
$probsrc = "$dirname/problems/$probdir/$probtitle{$$allids[0]}.problem"; |
} else { |
} else { |
$probsrc="$dirname/problems/$dirtitle/$$allids[0].problem"; |
$probsrc="$dirname/problems/$dirtitle/$probtitle{$$allids[0]}.problem"; |
} |
} |
} |
} |
print $fh qq|<resource id="1" src="$probsrc" type="start" title="question_0001"></resource>|; |
print $fh qq|<resource id="1" src="$probsrc" type="start" title="question_0001"></resource>|; |
Line 2441 sub build_problem_container {
|
Line 2696 sub build_problem_container {
|
my $probdir = $$catinfo{$catid}{title}.'_'.$catid; |
my $probdir = $$catinfo{$catid}{title}.'_'.$catid; |
$probdir =~ s/\s/_/g; |
$probdir =~ s/\s/_/g; |
$probdir =~ s/\W//g; |
$probdir =~ s/\W//g; |
$probsrc = "$dirname/problems/$probdir/$$allids[$j].problem"; |
$probsrc = "$dirname/problems/$probdir/$probtitle{$$allids[$j]}.problem"; |
} else { |
} else { |
$probsrc = "$dirname/problems/$dirtitle/$$allids[$j].problem"; |
$probsrc = "$dirname/problems/$dirtitle/$probtitle{$$allids[$j]}.problem"; |
} |
} |
} |
} |
print $fh qq| |
print $fh qq| |
Line 2461 sub build_problem_container {
|
Line 2716 sub build_problem_container {
|
} |
} |
|
|
sub write_bb5_questions { |
sub write_bb5_questions { |
my ($allids,$containerdir,$context,$settings,$dirname,$res,$allanswers,$allchoices,$total,$newdir,$cid,$cdom,$cnum) = @_; |
my ($allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$allanswers,$allchoices,$total,$newdir,$cid,$cdom,$cnum,$docroot) = @_; |
my $qnum = 0; |
my $qnum = 0; |
foreach my $id (@{$allids}) { |
foreach my $id (@{$allids}) { |
|
if ($$settings{$id}{ishtml} eq 'true') { |
|
$$settings{$id}{text} = &HTML::Entities::decode($$settings{$id}{text}); |
|
} |
|
if ($$settings{$id}{text} =~ m#<img src=['"]?(https?://[^\s]+/)([^/\s\'"]+)['"]?[^>]*>#) { |
|
if (&retrieve_image($context,$res,$dirname,$cdom,$cnum,$docroot,$destdir,$1,$2) eq 'ok') { |
|
$$settings{$id}{text} =~ s#(<img src=['"]?)(https?://[^\s]+/)([^/\s'"]+)(['"]?[^>]*>)#$1../../resfiles/$res/webimages/$3$4#g; |
|
} |
|
} |
|
$$settings{$id}{text} =~ s#(<img src=[^>]+)/*>#$1 />#gi; |
|
$$settings{$id}{text} =~ s#<br>#<br />#g; |
$qnum ++; |
$qnum ++; |
my $output; |
my $output; |
my $permcontainer = $containerdir; |
my $permcontainer = $containerdir; |
Line 2807 sub write_bb5_questions {
|
Line 3072 sub write_bb5_questions {
|
if ($context eq 'CSTR') { |
if ($context eq 'CSTR') { |
$output .= qq|</problem> |
$output .= qq|</problem> |
|; |
|; |
open(PROB,">$newdir/problems/$id.problem"); |
my $title = $$settings{title}; |
|
$title =~ s/\s/_/g; |
|
$title =~ s/\W//g; |
|
$title .= '_'.$id; |
|
open(PROB,">:utf8", "$newdir/$title.problem"); |
print PROB $output; |
print PROB $output; |
close PROB; |
close PROB; |
} else { |
} else { |
Line 2835 sub write_webct4_questions {
|
Line 3104 sub write_webct4_questions {
|
$allfeedback .= $feedback; |
$allfeedback .= $feedback; |
} |
} |
if ($$settings{$id}{texttype} eq 'text/html') { |
if ($$settings{$id}{texttype} eq 'text/html') { |
$$settings{$id}{text} = &HTML::Entities::decode($$settings{$id}{text}); |
$$settings{$id}{text} =~ s/(\&)(nbsp|gt|lt)(?!;)/$1$2;$3/gi; |
$$settings{$id}{text} = &Apache::lonxml::htmlclean($$settings{$id}{text}); |
$$settings{$id}{text} = &Apache::loncleanup::htmlclean($$settings{$id}{text}); |
$$settings{$id}{text} =~ s#(<img src=")([^>]+)>#$1../../resfiles/$2 />#gi; |
$$settings{$id}{text} =~ s#(<img src=["']?)([^>]+?)(/?>)#$1../../resfiles/$2 />#gi; |
$$settings{$id}{text} =~ s#<hr>#<hr />#g; |
$$settings{$id}{text} =~ s#<([bh])r>#<$1r />#g; |
# $$settings{$id}{text} =~ s#<p>#</p><p>#g; |
|
# $$settings{$id}{text} =~ s#</p></p>#</p>#; |
|
# $$settings{$id}{text} =~ s#<p></p>##g; |
|
$$settings{$id}{text} =~ s#<p>#<br /><br />#g; |
$$settings{$id}{text} =~ s#<p>#<br /><br />#g; |
$$settings{$id}{text} =~ s#<\\p>##g; |
$$settings{$id}{text} =~ s#</p>##g; |
} |
} |
if ($$settings{$id}{class} eq 'numerical') { |
if ($$settings{$id}{class} eq 'numerical') { |
foreach my $numid (@{$$settings{$id}{numids}}) { |
foreach my $numid (@{$$settings{$id}{numids}}) { |
Line 2864 sub write_webct4_questions {
|
Line 3130 sub write_webct4_questions {
|
$resourcedata{$symb.'randomize'} = 'yes'; |
$resourcedata{$symb.'randomize'} = 'yes'; |
$resourcedata{$symb.'maxfoils'} = 10; |
$resourcedata{$symb.'maxfoils'} = 10; |
if ($context eq 'CSTR') { |
if ($context eq 'CSTR') { |
$output = qq|<problem> |
unless ($$settings{$id}{class} eq 'numerical') { |
|
$output = qq|<problem> |
|; |
|; |
|
} |
} |
} |
$$total{prob} ++; |
$$total{prob} ++; |
if (exists($$settings{$id}{uri})) { |
if (exists($$settings{$id}{uri})) { |
Line 2926 sub write_webct4_questions {
|
Line 3194 sub write_webct4_questions {
|
} |
} |
if ($$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{texttype} eq 'text/html') { |
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} = &HTML::Entities::decode($$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text}); |
$$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} = &Apache::lonxml::htmlclean($$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#(<img src=")([^>]+)>#$1../../resfiles/$2 />#gi; |
$$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} =~ s#(<img src=")([^>]+)>#$1../../resfiles/$2 />#gi; |
$$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} =~ s#</?p>##g; |
$$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} =~ s#</?p>##g; |
|
|
Line 2968 sub write_webct4_questions {
|
Line 3236 sub write_webct4_questions {
|
} |
} |
if ($$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{texttype} eq 'text/html') { |
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} = &HTML::Entities::decode($$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text}); |
$$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} = &Apache::lonxml::htmlclean($$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#(<img src=")([^>]+)>#$1../../resfiles/$2 />#gi; |
$$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} =~ s#(<img src=")([^>]+)>#$1../../resfiles/$2 />#gi; |
$$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} =~ s#</?p>##g; |
$$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} =~ s#</?p>##g; |
Line 3000 sub write_webct4_questions {
|
Line 3268 sub write_webct4_questions {
|
|
|
$$settings{$id}{$grp}{$answer_id}{text} = &HTML::Entities::decode($$settings{$id}{$grp}{$answer_id}{text}); |
$$settings{$id}{$grp}{$answer_id}{text} = &HTML::Entities::decode($$settings{$id}{$grp}{$answer_id}{text}); |
$test_for_html = &test_for_html($$settings{$id}{$grp}{$answer_id}{text}); |
$test_for_html = &test_for_html($$settings{$id}{$grp}{$answer_id}{text}); |
$$settings{$id}{$grp}{$answer_id}{text} = &Apache::lonxml::chtmlclean($$settings{$id}{$grp}{$answer_id}{text}); |
$$settings{$id}{$grp}{$answer_id}{text} = &Apache::loncleanup::htmlclean($$settings{$id}{$grp}{$answer_id}{text}); |
$$settings{$id}{$grp}{$answer_id}{text} =~ s#(<img src=")([^>]+)>#$1../../resfiles/$2 />#gi; |
$$settings{$id}{$grp}{$answer_id}{text} =~ s#(<img src=")([^>]+)>#$1../../resfiles/$2 />#gi; |
$$settings{$id}{$grp}{$answer_id}{text} =~ s#</?p>##g; |
$$settings{$id}{$grp}{$answer_id}{text} =~ s#</?p>##g; |
} |
} |
Line 3029 sub write_webct4_questions {
|
Line 3297 sub write_webct4_questions {
|
} else { |
} else { |
$output .= qq| |
$output .= qq| |
<optionresponse max="10" randomize="yes"> |
<optionresponse max="10" randomize="yes"> |
<foilgroup options=$allmatchlist> |
<foilgroup options="$allmatchlist"> |
|; |
|; |
} |
} |
} else { |
} else { |
Line 3063 sub write_webct4_questions {
|
Line 3331 sub write_webct4_questions {
|
for (my $k=0; $k<@{$$allchoices{$id}}; $k++) { |
for (my $k=0; $k<@{$$allchoices{$id}}; $k++) { |
if ($$settings{$id}{$$allchoices{$id}[$k]}{texttype} eq 'text/html') { |
if ($$settings{$id}{$$allchoices{$id}[$k]}{texttype} eq 'text/html') { |
$$settings{$id}{$$allchoices{$id}[$k]}{text} = &HTML::Entities::decode($$settings{$id}{$$allchoices{$id}[$k]}{text}); |
$$settings{$id}{$$allchoices{$id}[$k]}{text} = &HTML::Entities::decode($$settings{$id}{$$allchoices{$id}[$k]}{text}); |
$$settings{$id}{$$allchoices{$id}[$k]}{text} = &Apache::lonxml::htmlclean($$settings{$id}{$$allchoices{$id}[$k]}{text}); |
$$settings{$id}{$$allchoices{$id}[$k]}{text} = &Apache::loncleanup::htmlclean($$settings{$id}{$$allchoices{$id}[$k]}{text}); |
$$settings{$id}{$$allchoices{$id}[$k]}{text} =~ s#(<img src=")([^>]+)>#$1../../resfiles/$2 />#gi; |
$$settings{$id}{$$allchoices{$id}[$k]}{text} =~ s#(<img src=")([^>]+)>#$1../../resfiles/$2 />#gi; |
$$settings{$id}{$$allchoices{$id}[$k]}{text} =~ s#</?p>##g; |
$$settings{$id}{$$allchoices{$id}[$k]}{text} =~ s#</?p>##g; |
} |
} |
Line 3220 sub write_webct4_questions {
|
Line 3488 sub write_webct4_questions {
|
} |
} |
} |
} |
} elsif ($$settings{$id}{class} eq 'numerical') { |
} elsif ($$settings{$id}{class} eq 'numerical') { |
|
my %mathfns = ( |
|
'abs' => 'abs', |
|
'acos' => 'acos', |
|
'asin' => 'asin', |
|
'atan' => 'atan', |
|
'ceil' => 'ceil', |
|
'cos' => 'cos', |
|
'exp' => 'exp', |
|
'fact' => 'factorial', |
|
'floor' => 'floor', |
|
'int' => 'int', |
|
'ln' => 'log', |
|
'log' => 'log', |
|
'max' => 'max', |
|
'min' => 'min', |
|
'round' => 'roundto', |
|
'sin' => 'sin', |
|
'sqrt' => 'sqrt', |
|
'tan' => 'tan', |
|
); |
|
|
my $scriptblock = qq| |
my $scriptblock = qq| |
<script type="loncapa/perl"> |
<script type="loncapa/perl"> |
|; |
|; |
foreach my $numid (@{$$settings{$id}{numids}}) { |
foreach my $numid (@{$$settings{$id}{numids}}) { |
my $formula = $$settings{$id}{$numid}{formula}; |
my $formula = $$settings{$id}{$numid}{formula}; |
|
my $pattern = join('|',(sort (keys (%mathfns)))); |
|
$formula =~ s/($pattern)/\&$mathfns{$1}/g; |
foreach my $var (keys %{$$settings{$id}{$numid}{vars}}) { |
foreach my $var (keys %{$$settings{$id}{$numid}{vars}}) { |
my $decnum = $$settings{$id}{$numid}{vars}{$var}{dec}; |
my $decnum = $$settings{$id}{$numid}{vars}{$var}{dec}; |
my $increment = '0.'; |
my $increment = '0.'; |
Line 3238 sub write_webct4_questions {
|
Line 3529 sub write_webct4_questions {
|
} |
} |
$increment .= '1'; |
$increment .= '1'; |
} |
} |
$formula =~ s/{($var)}/\$$1/g; |
$formula =~ s/{($var)}/(\$$1)/g; |
$formula =~ s/ln\(?([^\)])\)?/ &log($1) /g; |
|
$formula =~ s/sqrt/\&sqrt/g; |
|
$scriptblock .= qq| |
$scriptblock .= qq| |
\$$var=&random($$settings{$id}{$numid}{vars}{$var}{min},$$settings{$id}{$numid}{vars}{$var}{max},$increment); |
\$$var=&random($$settings{$id}{$numid}{vars}{$var}{min},$$settings{$id}{$numid}{vars}{$var}{max},$increment); |
|; |
|; |
Line 3250 sub write_webct4_questions {
|
Line 3539 sub write_webct4_questions {
|
</script> |
</script> |
|; |
|; |
if ($context eq 'CSTR') { |
if ($context eq 'CSTR') { |
$output = $scriptblock.$output; |
$output = "<problem>\n".$scriptblock.$output; |
my $ansformat = ''; |
my $ansformat = ''; |
my $sigfig = '0,15'; |
my $sigfig = '0,15'; |
if ($$settings{$id}{$numid}{format} eq 'sig') { |
if ($$settings{$id}{$numid}{format} eq 'sig') { |
Line 3271 sub write_webct4_questions {
|
Line 3560 sub write_webct4_questions {
|
} |
} |
my $unitentry = ''; |
my $unitentry = ''; |
if ($unit ne '') { |
if ($unit ne '') { |
$unitentry = 'unit='.$unit; |
$unitentry = 'unit="'.$unit.'"'; |
} |
} |
$output .= qq| |
$output .= qq| |
<numericalresponse $unitentry $ansformat answer="\$answervar"> |
<numericalresponse $unitentry $ansformat answer="\$answervar"> |
Line 3328 sub test_for_html {
|
Line 3617 sub test_for_html {
|
} |
} |
|
|
sub write_bb6_questions { |
sub write_bb6_questions { |
my ($allids,$containerdir,$context,$settings,$dirname,$res,$allanswers,$allchoices) = @_; |
my ($allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$total,$newdir,$cid,$cdom,$cnum,$docroot) = @_; |
|
my $qnum = 0; |
|
foreach my $id (@{$allids}) { |
|
my $questiontext = $$settings{$id}{question}{text}; |
|
my $question_texttype = $$settings{$id}{question}{texttype}; |
|
&process_html(\$questiontext,'bb6',$question_texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir); |
|
$qnum ++; |
|
my $output; |
|
my $permcontainer = $containerdir; |
|
$permcontainer =~ s#/home/httpd/html/userfiles#uploaded#; |
|
my $symb = $cid.'.'.$permcontainer.'___'.$qnum.'___lib/templates/simpleproblem.problem.0.'; |
|
my %resourcedata = (); |
|
for (my $i=0; $i<10; $i++) { |
|
my $iter = $i+1; |
|
$resourcedata{$symb.'text'.$iter} = ""; |
|
$resourcedata{$symb.'value'.$iter} = "unused"; |
|
$resourcedata{$symb.'position'.$iter} = "random"; |
|
} |
|
$resourcedata{$symb.'randomize'} = 'yes'; |
|
$resourcedata{$symb.'maxfoils'} = 10; |
|
if ($context eq 'CSTR') { |
|
$output = qq|<problem> |
|
|; |
|
} |
|
$$total{prob} ++; |
|
$questiontext .= &add_images_links('question',$settings,$id,$dirname,$res); |
|
if ($$settings{$id}{class} eq "Essay") { |
|
if ($context eq 'CSTR') { |
|
$output .= qq|<startouttext />$questiontext<endouttext /> |
|
<essayresponse> |
|
<textfield></textfield> |
|
</essayresponse> |
|
|; |
|
} else { |
|
$resourcedata{$symb.'questiontext'} = $questiontext; |
|
$resourcedata{$symb.'hiddenparts'} = '!essay'; |
|
$resourcedata{$symb.'questiontype'} = 'essay'; |
|
} |
|
} else { |
|
if ($context eq 'CSTR') { |
|
$output .= qq|<startouttext />$questiontext\n<endouttext />|; |
|
} else { |
|
$resourcedata{$symb.'questiontext'} = $questiontext; |
|
} |
|
my $numfoils = @{$$settings{$id}{answers}}; |
|
if (($$settings{$id}{class} eq 'Multiple Choice') || |
|
($$settings{$id}{class} eq 'True/False')) { |
|
if ($context eq 'CSTR') { |
|
$output .= qq| |
|
<radiobuttonresponse max="$numfoils" randomize="yes"> |
|
<foilgroup> |
|
|; |
|
} else { |
|
$resourcedata{$symb.'hiddenparts'} = '!radio'; |
|
$resourcedata{$symb.'questiontype'} = 'radio'; |
|
$resourcedata{$symb.'maxfoils'} = $numfoils; |
|
} |
|
for (my $k=0; $k<$numfoils; $k++) { |
|
my $iter = $k+1; |
|
my $answer_id = $$settings{$id}{answers}[$k]; |
|
my $answer_text = $$settings{$id}{$answer_id}{text}; |
|
my $texttype = $$settings{$id}{$answer_id}{texttype}; |
|
&process_html(\$answer_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir); |
|
$answer_text .= &add_images_links('response',$settings,$id,$dirname,$res); |
|
$output .= " <foil name=\"foil".$k."\" value=\""; |
|
if (grep/^$answer_id$/,@{$$settings{$id}{correctanswer}}) { |
|
$output .= "true\" location=\""; |
|
$resourcedata{$symb.'value'.$iter} = "true"; |
|
} else { |
|
$output .= "false\" location=\""; |
|
$resourcedata{$symb.'value'.$iter} = "false"; |
|
} |
|
if (lc ($$settings{$id}{$answer_id}{text}) =~ m/^\s?([Aa]ll)|([Nn]one)\s(of\s)?the\sabove\.?/) { |
|
$output .= "bottom\""; |
|
$resourcedata{$symb.'position'.$iter} = "bottom"; |
|
} else { |
|
$output .= "random\""; |
|
} |
|
$output .= '\><startouttext />'.$answer_text. |
|
'<endouttext /></foil>'."\n"; |
|
$resourcedata{$symb.'text'.$iter} = $answer_text; |
|
} |
|
if ($context eq 'CSTR') { |
|
chomp($output); |
|
$output .= qq| |
|
</foilgroup> |
|
<hintgroup showoncorrect="no"> |
|
<radiobuttonhint> |
|
</radiobuttonhint> |
|
<hintpart on="default"> |
|
<startouttext/><endouttext /> |
|
</hintpart> |
|
</hintgroup> |
|
</radiobuttonresponse> |
|
|; |
|
} |
|
} elsif ($$settings{$id}{class} eq 'Multiple Answer') { |
|
if ($context eq 'CSTR') { |
|
$output .= qq| |
|
<optionresponse max="$numfoils" randomize="yes"> |
|
<foilgroup options="('True','False')"> |
|
|; |
|
} else { |
|
$resourcedata{$symb.'newopt'} = ''; |
|
$resourcedata{$symb.'delopt'} = ''; |
|
$resourcedata{$symb.'options'} = "('True','False')"; |
|
$resourcedata{$symb.'hiddenparts'} = '!option'; |
|
$resourcedata{$symb.'questiontype'} = 'option'; |
|
$resourcedata{$symb.'maxfoils'} = $numfoils; |
|
} |
|
for (my $k=0; $k<$numfoils; $k++) { |
|
my $iter = $k+1; |
|
my $answer_id = $$settings{$id}{answers}[$k]; |
|
my $answer_text = $$settings{$id}{$answer_id}{text}; |
|
my $texttype = $$settings{$id}{$answer_id}{texttype}; |
|
&process_html(\$answer_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir); |
|
$answer_text .= &add_images_links('response',$settings,$id,$dirname,$res); |
|
|
|
$output .= " <foil name=\"foil".$k."\" value=\""; |
|
if (grep/^$answer_id$/,@{$$settings{$id}{correctanswer}}) { |
|
$output .= "True\""; |
|
$resourcedata{$symb.'value'.$iter} = "True"; |
|
} else { |
|
$output .= "False\""; |
|
$resourcedata{$symb.'value'.$iter} = "False"; |
|
} |
|
$output .= "\><startouttext />".$answer_text."<endouttext /></foil>\n"; |
|
$resourcedata{$symb.'text'.$iter} = $answer_text; |
|
} |
|
if ($context eq 'CSTR') { |
|
chomp($output); |
|
$output .= qq| |
|
</foilgroup> |
|
<hintgroup showoncorrect="no"> |
|
<optionhint> |
|
</optionhint> |
|
<hintpart on="default"> |
|
<startouttext/><endouttext /> |
|
</hintpart> |
|
</hintgroup> |
|
</optionresponse> |
|
|; |
|
} |
|
} elsif ($$settings{$id}{class} eq 'Ordering') { |
|
my @allorder = (); |
|
if ($context eq 'CSTR') { |
|
$output .= qq| |
|
<rankresponse max="$numfoils" randomize="yes"> |
|
<foilgroup> |
|
|; |
|
} else { |
|
$resourcedata{$symb.'newopt'} = ''; |
|
$resourcedata{$symb.'delopt'} = ''; |
|
$resourcedata{$symb.'hiddenparts'} = '!option'; |
|
$resourcedata{$symb.'questiontype'} = 'option'; |
|
$resourcedata{$symb.'maxfoils'} = $numfoils; |
|
} |
|
for (my $k=0; $k<$numfoils; $k++) { |
|
my $answer_id = $$settings{$id}{answers}[$k]; |
|
my $answer_text = $$settings{$id}{$answer_id}{text}; |
|
my $texttype = $$settings{$id}{$answer_id}{texttype}; |
|
&process_html(\$answer_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir); |
|
$answer_text .= &add_images_links('response',$settings,$id,$dirname,$res); |
|
my $iter = $k+1; |
|
if ($context eq 'CSTR') { |
|
$output .= " <foil location=\"random\" name=\"foil".$k."\" value=\"".$$settings{$id}{$answer_id}{order}."\"><startouttext />".$answer_text."<endouttext /></foil>\n"; |
|
} else { |
|
$resourcedata{$symb.'text'.$iter} = $answer_text; |
|
$resourcedata{$symb.'value'.$iter} = $$settings{$id}{$answer_id}{order}; |
|
if (!grep/^$$settings{$id}{$answer_id}{order}$/,@allorder) { |
|
push(@allorder,$$settings{$id}{$answer_id}{order}); |
|
} |
|
} |
|
} |
|
if ($context eq 'CSTR') { |
|
chomp($output); |
|
$output .= qq| |
|
</foilgroup> |
|
</rankresponse> |
|
|; |
|
} else { |
|
@allorder = sort {$a <=> $b} @allorder; |
|
$resourcedata{$symb.'options'} = "('".join("','",@allorder)."')"; |
|
} |
|
} elsif ($$settings{$id}{class} eq 'Fill in the Blank') { |
|
my $numerical = 1; |
|
if ($context eq 'DOCS') { |
|
$numerical = 0; |
|
} else { |
|
for (my $k=0; $k<@{$$settings{$id}{correctanswer}}; $k++) { |
|
if ($$settings{$id}{correctanswer}[$k] =~ m/([^\d\.]|\.\.)/) { |
|
$numerical = 0; |
|
} |
|
} |
|
} |
|
if ($numerical) { |
|
my $numans; |
|
my $tol; |
|
if (@{$$settings{$id}{correctanswer}} == 1) { |
|
$tol = 5; |
|
$numans = $$settings{$id}{correctanswer}[0]; |
|
} else { |
|
my $min = $$settings{$id}{correctanswer}[0];; |
|
my $max = $min; |
|
for (my $k=1; $k<@{$$settings{$id}{correctanswer}}; $k++) { |
|
if ($$settings{$id}{correctanswer}[$k] <= $min) { |
|
$min = $$settings{$id}{correctanswer}[$k]; |
|
} |
|
if ($$settings{$id}{correctanswer}[$k] >= $max) { |
|
$max = $$settings{$id}{correctanswer}[$k]; |
|
} |
|
} |
|
$numans = ($max + $min)/2; |
|
$tol = 100*($max - $min)/($numans*2); |
|
$tol = 5; |
|
} |
|
if ($context eq 'CSTR') { |
|
$output .= qq| |
|
<numericalresponse answer="$numans"> |
|
<responseparam type="tolerance" default="$tol%" name="tol" description="Numerical Tolerance" /> |
|
<responseparam name="sig" type="int_range,0-16" default="0,15" description="Significant Figures" |
|
/> |
|
<textline /> |
|
</numericalresponse> |
|
<hintgroup showoncorrect="no"> |
|
<numericalhint> |
|
</numericalhint> |
|
<hintpart on="default"> |
|
<startouttext/><endouttext /> |
|
</hintpart> |
|
</hintgroup> |
|
|; |
|
} |
|
} else { |
|
if ($context eq 'DOCS') { |
|
$resourcedata{$symb.'hiddenparts'} = '!string'; |
|
$resourcedata{$symb.'questiontype'} = 'string'; |
|
$resourcedata{$symb.'maxfoils'} = 1; |
|
$resourcedata{$symb.'hiddenparts'} = '!string'; |
|
$resourcedata{$symb.'stringtype'} = 'ci'; |
|
$resourcedata{$symb.'stringanswer'} = $$settings{$id}{correctanswer}[0]; |
|
} else { |
|
if (@{$$settings{$id}{correctanswer}} == 1) { |
|
$output .= qq| |
|
<stringresponse answer="$$settings{$id}{correctanswer}[0];" type="ci"> |
|
<textline> |
|
</textline> |
|
</stringresponse> |
|
<hintgroup showoncorrect="no"> |
|
<stringhint type="cs"> |
|
</stringhint> |
|
<hintpart on="default"> |
|
<startouttext/><endouttext /> |
|
</hintpart> |
|
</hintgroup> |
|
|; |
|
} else { |
|
my @answertext = (); |
|
for (my $k=0; $k<@{$$settings{$id}{correctanswer}}; $k++) { |
|
my $answer_text = $$settings{$id}{correctanswer}[$k]; |
|
$answer_text =~ s/\|/\|/g; |
|
push @answertext, $answer_text; |
|
} |
|
my $regexpans = join('|',@answertext); |
|
$regexpans = '/^('.$regexpans.')\b/'; |
|
$output .= qq| |
|
<stringresponse answer="$regexpans" type="re"> |
|
<textline> |
|
</textline> |
|
</stringresponse> |
|
<hintgroup showoncorrect="no"> |
|
<stringhint type="cs"> |
|
</stringhint> |
|
<hintpart on="default"> |
|
<startouttext/><endouttext /> |
|
</hintpart> |
|
</hintgroup> |
|
|; |
|
} |
|
} |
|
} |
|
} elsif ($$settings{$id}{class} eq "Matching") { |
|
my @allmatchers = (); |
|
my %matchtext = (); |
|
if ($context eq 'CSTR') { |
|
$output .= qq| |
|
<matchresponse max="10" randomize="yes"> |
|
<foilgroup> |
|
<itemgroup> |
|
|; |
|
} else { |
|
$resourcedata{$symb.'newopt'} = ''; |
|
$resourcedata{$symb.'delopt'} = ''; |
|
$resourcedata{$symb.'hiddenparts'} = '!option'; |
|
$resourcedata{$symb.'questiontype'} = 'option'; |
|
$resourcedata{$symb.'maxfoils'} = $numfoils; |
|
} |
|
for (my $k=0; $k<$$settings{$id}{allchoices}; $k++) { |
|
my $choice_id = 'rightmatch'.$k; |
|
my $choice_text = $$settings{$id}{$choice_id}{text}; |
|
my $texttype = $$settings{$id}{$choice_id}{texttype}; |
|
my $choice_plaintext = &remove_html($choice_text); |
|
&process_html(\$choice_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir); |
|
$choice_text .= &add_images_links($choice_id,$settings,$id,$dirname,$res); |
|
push(@allmatchers,$choice_plaintext); |
|
if ($context eq 'CSTR') { |
|
$output .= qq| |
|
<item name="$choice_id"> |
|
<startouttext />$choice_text<endouttext /> |
|
</item> |
|
|; |
|
} |
|
} |
|
if ($context eq 'CSTR') { |
|
$output .= qq| |
|
</itemgroup> |
|
|; |
|
} |
|
for (my $k=0; $k<$numfoils; $k++) { |
|
my $answer_id = $$settings{$id}{answers}[$k]; |
|
my $answer_text = $$settings{$id}{$answer_id}{text}; |
|
my $texttype = $$settings{$id}{$answer_id}{texttype}; |
|
&process_html(\$answer_text,'bb6',$texttype,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir); |
|
$answer_text .= &add_images_links($answer_id,$settings,$id,$dirname,$res); |
|
if ($context eq 'CSTR') { |
|
$output .= ' |
|
<foil location="random" value="rightmatch'.$$settings{$id}{$$settings{$id}{$answer_id}{correctanswer}}{order}.'" name="'.$answer_id.'"> |
|
<startouttext />'.$answer_text.'<endouttext /> |
|
</foil> |
|
'; |
|
} else { |
|
my $iter = $k+1; |
|
$resourcedata{$symb.'value'.$iter} = "$allmatchers[$$settings{$id}{$$settings{$id}{$answer_id}{correctanswer}}{order}]"; |
|
$resourcedata{$symb.'text'.$iter} = $answer_text; |
|
} |
|
} |
|
if ($context eq 'CSTR') { |
|
$output .= qq| |
|
</foilgroup> |
|
</matchresponse> |
|
|; |
|
} else { |
|
$resourcedata{$symb.'options'} = "('".join("','",@allmatchers)."')"; |
|
} |
|
} |
|
} |
|
if ($context eq 'CSTR') { |
|
|
|
$output .= qq| |
|
<postanswerdate> |
|
$$settings{$id}{solutionfeedback}{text} |
|
</postanswerdate> |
|
</problem> |
|
|; |
|
my $title = $$settings{title}; |
|
$title =~ s/\s/_/g; |
|
$title =~ s/\W//g; |
|
$title .= '_'.$id; |
|
open(PROB,">:utf8", "$newdir/$title.problem"); |
|
print PROB $output; |
|
close PROB; |
|
} else { |
|
# put %resourcedata; |
|
my $reply=&Apache::lonnet::cput |
|
('resourcedata',\%resourcedata,$cdom,$cnum); |
|
} |
|
} |
|
} |
|
|
|
sub retrieve_image { |
|
my ($context,$res,$dirname,$cdom,$cname,$docroot,$destdir,$urlpath,$filename) = @_; |
|
my $contents; |
|
my $url = $urlpath.$filename; |
|
my $ua=new LWP::UserAgent; |
|
my $request=new HTTP::Request('GET',$url); |
|
my $response=$ua->request($request); |
|
if ($response->is_success) { |
|
$contents = $response->content; |
|
if (!-e "$docroot/$res") { |
|
mkdir("$docroot/$res",0755); |
|
} |
|
if (!-e "$docroot/$res/webimages") { |
|
mkdir("$docroot/$res/webimages",0755); |
|
} |
|
open(my $fh,">$docroot/$res/webimages/$filename"); |
|
print $fh $contents; |
|
close($fh); |
|
if ($context eq 'DOCS') { |
|
my $chome = &Apache::lonnet::homeserver($cname,$cdom); |
|
my $copyfile = $dirname.'/'.$filename; |
|
my $source = "$docroot/$res/webimages/$filename"; |
|
my $fileresult; |
|
if (-e $source) { |
|
$fileresult = &Apache::lonnet::process_coursefile('copy',$cname,$cdom,$chome,$copyfile,$source); |
|
} |
|
return $fileresult; |
|
} elsif ($context eq 'CSTR') { |
|
if (!-e "$destdir/resfiles/$res") { |
|
mkdir("$destdir/resfiles/$res",0755); |
|
} |
|
if (!-e "$destdir/resfiles/$res/webimages") { |
|
mkdir("$destdir/resfiles/$res/webimages",0755); |
|
} |
|
rename("$docroot/$res/webimages/$filename","$destdir/resfiles/$res/webimages/$filename"); |
|
return 'ok'; |
|
} |
|
} else { |
|
return -1; |
|
} |
} |
} |
|
|
# ---------------------------------------------------------------- Process Blackboard Announcements |
# ---------------------------------------------------------------- Process Blackboard Announcements |
Line 3873 $linktag
|
Line 4570 $linktag
|
} |
} |
} |
} |
|
|
# ---------------------------------------------------------------- WebCT assessments |
sub process_html { |
sub webct4_assessment { |
my ($text,$caller,$html_cond,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir) = @_; |
my ($res,$docroot,$destdir,$settings,$dom,$user,$type,$title,$resrcfiles) = @_; |
|
print STDERR "webct assessment detected - $res, $docroot, $destdir, $type,$title\n"; |
if ($caller eq 'bb5') { |
|
if ($html_cond eq 'true') { |
|
$$text = &HTML::Entities::decode($$text); |
|
} |
|
} elsif ($caller eq 'bb6') { |
|
if ($html_cond eq 'HTML') { |
|
$$text = &HTML::Entities::decode($$text); |
|
} |
|
} |
|
if ($$text =~ m#<img src=['"]?(https?://[^\s]+/)([^/\s\'"]+)['"]?[^>]*>#) { |
|
if (&retrieve_image($context,$res,$dirname,$cdom,$cnum,$docroot,$destdir,$1,$2) eq 'ok') { |
|
$$text =~ s#(<img src=['"]?)(https?://[^\s]+/)([^/\s'"]+)(['"]?[^>]*>)#$1../../resfiles/$res/webimages/$3$4#g; |
|
} |
|
} |
|
$$text =~ s#(<img src=[^>]+)/*>#$1 />#gi; |
|
$$text =~ s#<br>#<br />#g; |
|
return; |
|
} |
|
|
|
sub add_images_links { |
|
my ($type,$settings,$id,$dirname,$res) = @_; |
|
my ($image,$imglink,$url); |
|
if ((defined($$settings{$id}{$type}{image})) && ($$settings{$id}{$type}{image} ne '')) { |
|
if ( $$settings{$id}{$type}{style} eq 'Inline' ) { |
|
$image = qq|<br /><img src="../../resfiles/$res/$$settings{$id}{$type}{image}" alt="$$settings{$id}{$type}{label}"/><br />|; |
|
} else { |
|
$imglink = qq|<br /><a href="../../resfiles/$res/$$settings{$id}{$type}{image}">$$settings{$id}{$type}{label}</a><br />|; |
|
} |
|
} |
|
if ((defined($$settings{$id}{$type}{link})) && ($$settings{$id}{$type}{link} ne '' )) { |
|
$url = qq|<br /><a href="$$settings{$id}{$type}{link}">$$settings{$id}{$type}{linkname}</a><br />|; |
|
} |
|
return $image.$imglink.$url; |
} |
} |
|
|
|
sub remove_html { |
|
my ($choice_text) = @_; |
|
return $choice_text; |
|
} |
|
|
|
|
1; |
1; |
__END__ |
__END__ |