- $$settings{$id}{$allanswers{$id}[$k]}{text}
+
+ $$settings{$id}{$$allanswers{$id}[$k]}{text}
|;
} else {
my $iter = $k+1;
- $resourcedata{$symb.'value'.$iter} = $matchtext{$$settings{$id}{$allanswers{$id}[$k]}{choice_id}};
- $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$allanswers{$id}[$k]}{text};
+ $resourcedata{$symb.'value'.$iter} = $matchtext{$$settings{$id}{$$allanswers{$id}[$k]}{choice_id}};
+ $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$$allanswers{$id}[$k]}{text};
}
}
if ($context eq 'CSTR') {
@@ -2074,7 +2949,523 @@ sub process_assessment {
if ($context eq 'CSTR') {
$output .= qq|
|;
- open(PROB,">$newdir/$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 {
+# put %resourcedata;
+ my $reply=&Apache::lonnet::cput
+ ('resourcedata',\%resourcedata,$cdom,$cnum);
+ }
+ }
+}
+
+sub write_webct4_questions {
+ my ($alldbquestids,$context,$settings,$dirname,$allanswers,$allchoices,$total,$cid,$cdom,$cnum,$destdir,$catinfo) = @_;
+ my $qnum = 0;
+ foreach my $id (@{$alldbquestids}) {
+ $qnum ++;
+ my $output;
+ my $permcontainer = $destdir.'/sequences/'.$id.'.sequence';
+ my $allfeedback;
+ my $questionimage;
+ foreach my $fdbk (@{$$settings{$id}{feedback}}) {
+ my $feedback = $$settings{$id}{$fdbk}{text};
+ if ($$settings{$id}{$fdbk}{texttype} eq 'text/html') {
+ $feedback = &HTML::Entities::decode($feedback);
+ }
+ $allfeedback .= $feedback;
+ }
+ if ($$settings{$id}{texttype} eq 'text/html') {
+ $$settings{$id}{text} =~ s/(\&)(nbsp|gt|lt)(?!;)/$1$2;$3/gi;
+ $$settings{$id}{text} = &Apache::loncleanup::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#
##g;
+ }
+ if ($$settings{$id}{class} eq 'numerical') {
+ foreach my $numid (@{$$settings{$id}{numids}}) {
+ foreach my $var (keys %{$$settings{$id}{$numid}{vars}}) {
+ $$settings{$id}{text} =~ s/{($var)}/\$$1 /g;
+ }
+ }
+ }
+ $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') {
+ unless ($$settings{$id}{class} eq 'numerical') {
+ $output = qq|
+|;
+ }
+ }
+ $$total{prob} ++;
+ if (exists($$settings{$id}{uri})) {
+ if ($$settings{$id}{imagtype} =~ /^image\//) {
+ $questionimage = ''."\n";
+ }
+ }
+ if ($$settings{$id}{class} eq "paragraph") {
+ if ($context eq 'CSTR') {
+ $output .= qq|$$settings{$id}{text}
$questionimage
+
+
+
+
+ $allfeedback
+
+|;
+ } else {
+ $resourcedata{$symb.'questiontext'} = ''.$$settings{$id}{text}.'
'.$questionimage;
+ $resourcedata{$symb.'hiddenparts'} = '!essay';
+ $resourcedata{$symb.'questiontype'} = 'essay';
+ }
+ } else {
+ if ($context eq 'CSTR') {
+ $output .= qq|$$settings{$id}{text}
$questionimage\n|;
+ } else {
+ $resourcedata{$symb.'questiontext'} = ''.$$settings{$id}{text}.'
'.$questionimage;
+ }
+ if ($$settings{$id}{class} eq 'multiplechoice') {
+ foreach my $list (@{$$settings{$id}{lists}}) {
+ my $numfoils = @{$$allanswers{$id}{$list}};
+ if ($$settings{$id}{$list}{rcardinality} eq 'Single') {
+ if ($context eq 'CSTR') {
+ $output .= qq|
+
+
+|;
+ } else {
+ $resourcedata{$symb.'hiddenparts'} = '!radio';
+ $resourcedata{$symb.'questiontype'} = 'radio';
+ $resourcedata{$symb.'maxfoils'} = $numfoils;
+ }
+ for (my $k=0; $k<@{$$allanswers{$id}{$list}}; $k++) {
+ my $iter = $k+1;
+ $output .= " ".$$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text};
+ $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text};
+ $output .= ''."\n";
+ }
+ if ($context eq 'CSTR') {
+ chomp($output);
+ $output .= qq|
+
+
+|;
+ }
+ } else {
+ if ($context eq 'CSTR') {
+ $output .= qq|
+
+
+|;
+ } 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<@{$$allanswers{$id}{$list}}; $k++) {
+ my $iter = $k+1;
+ $output .= " ".$$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text}."
\n";
+ $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text};
+ }
+ if ($context eq 'CSTR') {
+ chomp($output);
+ $output .= qq|
+
+
+|;
+ }
+ }
+ }
+ } elsif ($$settings{$id}{class} eq 'match') {
+ my %allmatchers = ();
+ my @allmatch = ();
+ my %matchtext = ();
+ my $anscount = 0;
+ my %ansnum = ();
+ my $maxfoils = 0;
+ my $test_for_html = 0;
+ foreach my $grp (@{$$allchoices{$id}}) {
+ $maxfoils += @{$$settings{$id}{$grp}{correctanswer}};
+ foreach my $answer_id (@{$$allanswers{$id}{$grp}}) {
+ if ($$settings{$id}{$grp}{$answer_id}{texttype} eq '/text/html') {
+
+ $$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});
+ $$settings{$id}{$grp}{$answer_id}{text} = &Apache::loncleanup::htmlclean($$settings{$id}{$grp}{$answer_id}{text});
+ $$settings{$id}{$grp}{$answer_id}{text} =~ s#(
+
+
+|;
+ } else {
+ $output .= qq|
+
+
+|;
+ }
+ } else {
+ $resourcedata{$symb.'newopt'} = '';
+ $resourcedata{$symb.'delopt'} = '';
+ $resourcedata{$symb.'hiddenparts'} = '!option';
+ $resourcedata{$symb.'questiontype'} = 'option';
+ $resourcedata{$symb.'maxfoils'} = $maxfoils;
+ }
+ my $iter = 0;
+ foreach my $match (@allmatch) {
+ $iter ++;
+ if ($context eq 'CSTR') {
+ if ($test_for_html) {
+ $output .= qq|
+-
+$match
+
+|;
+ }
+ }
+ }
+ if ($context eq 'CSTR') {
+ if ($test_for_html) {
+ $output .= qq|
+
+|;
+ }
+ }
+ $iter = 0;
+ for (my $k=0; $k<@{$$allchoices{$id}}; $k++) {
+ 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} = &Apache::loncleanup::htmlclean($$settings{$id}{$$allchoices{$id}[$k]}{text});
+ $$settings{$id}{$$allchoices{$id}[$k]}{text} =~ s#(
+ $$settings{$id}{$$allchoices{$id}[$k]}{text}
+
+
+|;
+ }
+ }
+ if ($context eq 'DOCS') {
+ $resourcedata{$symb.'value'.$iter} = $matchtext{$ansnum{$$allchoices{$id}[$k]}[0]};
+ $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$$allchoices{$id}[0]}{text};
+ }
+ }
+ if ($context eq 'CSTR') {
+ $output .= qq|
+
+|;
+ if ($test_for_html) {
+ $output .= qq|
+
+|;
+ } else {
+ $output .= qq|
+