--- loncom/imspackages/imsprocessor.pm 2005/04/07 06:56:22 1.19
+++ loncom/imspackages/imsprocessor.pm 2005/10/14 22:28:56 1.29
@@ -24,6 +24,9 @@
package Apache::imsprocessor;
use Apache::lonnet;
+use Apache::loncleanup;
+use LWP::UserAgent;
+use HTTP::Request::Common;
use LONCAPA::Configuration;
use strict;
@@ -1724,7 +1727,7 @@ sub parse_bb5_assessment {
$id = $attr->{id};
} elsif ( ($state[0] eq $toptag{$container}) && ($state[1] =~ m/^QUESTION_(\w+)$/) && ($state[2] eq "BODY") && ($state[3] eq "FLAGS") ) {
if ($state[4] eq "ISHTML") {
- $$settings{$id}{html} = $attr->{value};
+ $$settings{$id}{ishtml} = $attr->{value};
} elsif ($state[4] eq "ISNEWLINELITERAL") {
$$settings{$id}{newline} = $attr->{value};
}
@@ -1824,8 +1827,180 @@ sub parse_bb5_assessment {
}
sub parse_bb6_assessment {
- my ($res,$docroot,$container,$settings,$allanswers,$allchoices,$allids) = @_;
- return;
+ my ($res,$docroot,$container,$settings,$allanswers,$allchoices,$allids) = @_;
+ my $xmlfile = $docroot.'/'.$res.".dat";
+ my @state = ();
+ my $id; # the current question ID
+ my $list; # the current list ID for multiple choice questions
+ my $response; # the current response ID
+ my $currtexttype;
+ my @curr_block = ();
+ my $curr_shuffle;
+ my $curr_class;
+ my $curr_matchitem;
+ my $curr_block_type;
+ my $curr_feedback_type;
+ 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") {
+ $currtexttype = $attr->{type};
+ }
+ if ("@state" eq "questestinterop section item presentation flow") {
+ $curr_block[0] = $attr->{class};
+ if ($curr_block[0] eq 'RESPONSE_BLOCK') {
+ $curr_block_type = 'response';
+ } elsif ($curr_block[0] eq 'RIGHT_MATCH_BLOCK') {
+ $curr_block_type = 'rightmatch';
+ }
+ }
+ if ("@state" eq "questestinterop section item presentation flow flow") {
+ $curr_block[1] = $attr->{class};
+ if ($curr_block[1] eq 'QUESTION_BLOCK') {
+ $curr_block_type = 'question';
+ }
+ }
+ if ("@state" eq "questestinterop section item presentation flow flow flow") {
+ $curr_block[2] = $attr->{class};
+ }
+ if ("@state" eq "questestinterop section item presentation flow flow flow material mat_extension mat_formatted_text") {
+ $$settings{$id}{$curr_block_type}{texttype} = $attr->{texttype};
+ $currtexttype = $attr->{texttype};
+ }
+ if ("@state" eq "questestinterop section item presentation flow flow flow 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 "questestinterop section item presentation flow flow flow material mattext") {
+ $$settings{$id}{$curr_block_type}{link} = $attr->{uri};
+ }
+ if ("@state" eq "questestinterop section item presentation flow response_lid render_choice") {
+ $curr_shuffle = $attr->{shuffle};
+ }
+ if ("@state" eq "questestinterop section item presentation flow response_lid") { $response = $attr->{ident};
+ if ($curr_class eq 'Matching') {
+ %{$$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 "questestinterop section item presentation flow response_lid render_choice flow response_label") {
+ if (($curr_class eq 'Multiple Choice') || ($curr_class eq 'Multiple Answer') || ($curr_class eq 'Order')) {
+ $list = $attr->{ident};
+ push(@{$$settings{$id}{lists}},$list);
+ $$settings{$id}{$list}{randomize} = $curr_shuffle;
+ %{$$settings{$id}{$list}} = ();
+ @{$$allanswers{$id}{$list}} = ();
+ @{$$settings{$id}{$list}{correctanswer}} = ();
+ } elsif ($curr_class eq 'Matching') {
+ push(@{$$settings{$id}{$response}{items}},$list);
+ }
+ }
+ if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow response_label flow_mat material matapplication") {
+ $$settings{$id}{$list}{filetype} = $attr->{embedded};
+ $$settings{$id}{$list}{label} = $attr->{label};
+ $$settings{$id}{$list}{uri} = $attr->{uri};
+ }
+ if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow response_label flow_mat material mattext") {
+ $$settings{$id}{$list}{link} = $attr->{uri};
+ }
+ if ("@state" eq "questestinterop section item resprocessing respcondition conditionvar varequal") {
+ if ($curr_class eq 'Matching') {
+ $curr_matchitem = $attr->{respident};
+ }
+ }
+ if ("@state" eq "questestinterop section item itemfeedback") {
+ $curr_feedback_type = $attr->{ident};
+ }
+ if ("@state" eq "questestinterop section item itemfeedback 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 "questestinterop section item itemfeedback 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;
+ } elsif ("@state" eq "questestinterop assessment presentation_material flow_mat material mat_extension mat_formattedtext") {
+ $$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}{lists}} = ();
+ %{$$settings{$id}{question}} = ();
+ %{$$settings{$id}{correctfeedback}} = ();
+ %{$$settings{$id}{incorrectfeedback}} = ();
+ %{$$settings{$id}{solutionfeedback}} = ();
+ %{$$settings{$id}{question}} = ();
+ %{$$settings{$id}{response}} = ();
+ }
+ if ("@state" eq "questestinterop assessment section item itemmetadata bbmd_questiontype") {
+ $$settings{$id}{class} = $text;
+ $curr_class = $text;
+ }
+ if ("@state" eq "questestinterop assessment section item presentation flow flow flow material mat_extension mat_formatted_text") {
+ $$settings{$id}{$curr_block_type}{text} = $text;
+ }
+ if ("@state" eq "questestinterop section item presentation flow flow flow material mattext") {
+ $$settings{$id}{$curr_block_type}{linktext} = $text;
+ }
+ if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow response_label flow_mat material mat_extension mat_formatted_text") {
+ $$settings{$id}{$list}{text} = $text;
+ }
+ if ("@state" eq "questestinterop section item presentation flow response_lid render_choice flow response_label flow_mat material mattext") {
+ $$settings{$id}{$list}{linktext} = $text;
+ }
+ if ("@state" eq "questestinterop section item resprocessing respcondition conditionvar varequal") {
+ if ($curr_class eq 'Multiple Choice') {
+ $$settings{$id}{$list}{correctanswer}[0] = $text;
+ } elsif ($curr_class eq 'True/False') {
+ $$settings{$id}{correctanswer} = $text;
+ } elsif ($curr_class eq 'Matching') {
+ $$settings{$id}{$curr_matchitem}{correctanswer} = $text;
+ } elsif ($curr_class eq 'Fill in the Blank') {
+ push(@{$$settings{$id}{$list}{correctanswer}},$text);
+ }
+ }
+ if ("@state" eq "questestinterop section item resprocessing respcondition conditionvar and varequal") {
+ push(@{$$settings{$id}{$list}{correctanswer}},$text);
+ }
+ if ("@state" eq "questestinterop section item itemfeedback flow_mat flow_mat material mat_extension mat_formattedtext") {
+ $$settings{$id}{$curr_feedback_type.'feedback'}{text} = $text;
+ }
+ if ("@state" eq "questestinterop section item itemfeedback 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 {
@@ -2092,7 +2267,7 @@ sub parse_webct4_questionDB {
$$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") {
- my $unitid = $attr->{ident};
+ $unitid = $attr->{ident};
%{$$settings{$id}{$numid}{$unitid}} = ();
push(@{$$settings{$id}{$numid}{units}},$unitid);
$$settings{$id}{$numid}{$unitid}{value} = $attr->{value};
@@ -2342,7 +2517,7 @@ sub process_assessment {
if (!-e "$destdir/problems/$seqname") {
mkdir("$destdir/problems/$seqname",0755);
}
- my $newdir = "$destdir/problems/$seqname";
+ $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);
}
@@ -2370,14 +2545,18 @@ sub process_assessment {
if (!-e "$destdir/problems/$dirtitle") {
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') {
- &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') {
- &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,\%allanswers,\%allchoices,$total,$newdir,$cid,$cdom,$cnum);
}
}
@@ -2411,7 +2590,11 @@ sub build_problem_container {
my $probsrc = "/res/lib/templates/simpleproblem.problem";
if ($context eq 'CSTR') {
foreach my $id (@{$allids}) {
- $probtitle{$id} = $$settings{$id}{title};
+ 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;
@@ -2423,7 +2606,7 @@ sub build_problem_container {
$probdir =~ s/\W//g;
$probsrc = "$dirname/problems/$probdir/$probtitle{$$allids[0]}.problem";
} else {
- $probsrc="$dirname/problems/$dirtitle/$$allids[0].problem";
+ $probsrc="$dirname/problems/$dirtitle/$probtitle{$$allids[0]}.problem";
}
}
print $fh qq|
#
#g;
$qnum ++;
my $output;
my $permcontainer = $containerdir;
@@ -2811,7 +3004,11 @@ sub write_bb5_questions {
if ($context eq 'CSTR') {
$output .= qq|
|;
- 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;
close PROB;
} else {
@@ -2839,15 +3036,12 @@ sub write_webct4_questions {
$allfeedback .= $feedback;
}
if ($$settings{$id}{texttype} eq 'text/html') {
- $$settings{$id}{text} = &HTML::Entities::decode($$settings{$id}{text});
- $$settings{$id}{text} = &Apache::lonxml::htmlclean($$settings{$id}{text});
- $$settings{$id}{text} =~ s#(]+?)(/?>)#$1../../resfiles/$2 />#gi;
+ $$settings{$id}{text} =~ s#<([bh])r>#<$1r />#g;
$$settings{$id}{text} =~ s#
#
#g;
- $$settings{$id}{text} =~ s#<\\p>##g;
+ $$settings{$id}{text} =~ s#