--- loncom/imspackages/imsprocessor.pm 2005/04/07 06:56:22 1.19 +++ loncom/imspackages/imsprocessor.pm 2006/03/24 17:16:07 1.33 @@ -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; @@ -41,7 +44,17 @@ 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}} = ( board => 'BOARD', @@ -352,7 +365,7 @@ sub target_resources { } sub copy_resources { - my ($context,$cms,$hrefs,$tempdir,$targets,$url,$crs,$cdom,$chome,$destdir,$timenow) = @_; + my ($context,$cms,$hrefs,$tempdir,$targets,$url,$crs,$cdom,$destdir,$timenow) = @_; if ($context eq 'DOCS') { foreach my $key (sort keys %{$hrefs}) { if (grep/^$key$/,@{$targets}) { @@ -380,7 +393,7 @@ sub copy_resources { $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); } } } @@ -498,10 +511,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') { @@ -511,15 +524,15 @@ 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); 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); 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); push @{$surveys}, $key; @@ -1192,12 +1205,12 @@ sub process_group { # ---------------------------------------------------------------- Process Blackboard Staff sub process_staff { - my ($res,$docroot,$dirname,$destdir,$settings,$resrcfiles) = @_; + my ($res,$docroot,$destdir,$settings,$resrcfiles) = @_; my $xmlfile = $docroot.'/'.$res.".dat"; my $filecount = 0; my @state; %{$$settings{name}} = (); - %{$$settings{office}} = (); + %{$$settings{office}} = (); my $p = HTML::Parser->new ( @@ -1350,7 +1363,7 @@ sub process_staff { |; if ( defined($$settings{image}) ) { $staffentry .= qq| - + |; } $staffentry .= qq| @@ -1373,7 +1386,7 @@ $staffentry # ---------------------------------------------------------------- Process Blackboard Links sub process_link { - my ($res,$docroot,$dirname,$destdir,$settings,$resrcfiles) = @_; + my ($res,$docroot,$destdir,$settings,$resrcfiles) = @_; my $xmlfile = $docroot.'/'.$res.".dat"; my @state = (); my $p = HTML::Parser->new @@ -1724,7 +1737,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 +1837,238 @@ sub parse_bb5_assessment { } sub parse_bb6_assessment { - my ($res,$docroot,$container,$settings,$allanswers,$allchoices,$allids) = @_; - return; + my ($res,$docroot,$container,$settings,$allids) = @_; + 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 { @@ -2092,7 +2335,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}; @@ -2296,7 +2539,7 @@ sub process_assessment { if ($cms eq 'bb5') { &parse_bb5_assessment($res,$docroot,$container,$settings,\%allanswers,\%allchoices,\@allids); } 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') { unless($$dbparse) { &parse_webct4_questionDB($docroot,$$resources{$res}{file},$catinfo,$qzdbsettings,\%alldbanswers,\%alldbchoices,\@alldbquestids); @@ -2342,7 +2585,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 +2613,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,$total,$newdir,$cid,$cdom,$cnum,$docroot); } } @@ -2411,7 +2658,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 +2674,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||; @@ -2447,7 +2698,7 @@ sub build_problem_container { $probdir =~ s/\W//g; $probsrc = "$dirname/problems/$probdir/$probtitle{$$allids[$j]}.problem"; } else { - $probsrc = "$dirname/problems/$dirtitle/$$allids[$j].problem"; + $probsrc = "$dirname/problems/$dirtitle/$probtitle{$$allids[$j]}.problem"; } } print $fh qq| @@ -2465,9 +2716,25 @@ sub build_problem_container { } 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 $pathstart; + if ($context eq 'CSTR') { + $pathstart = '../..'; + } else { + $pathstart = $dirname; + } foreach my $id (@{$allids}) { + if ($$settings{$id}{ishtml} eq 'true') { + $$settings{$id}{text} = &HTML::Entities::decode($$settings{$id}{text}); + } + if ($$settings{$id}{text} =~ m#]*>#) { + if (&retrieve_image($context,$res,$dirname,$cdom,$cnum,$docroot,$destdir,$1,$2) eq 'ok') { + $$settings{$id}{text} =~ s#(]*>)#$1$pathstart/resfiles/$res/webimages/$3$4#g; + } + } + $$settings{$id}{text} =~ s#(]+)/*>#$1 />#gi; + $$settings{$id}{text} =~ s#
#
#g; $qnum ++; my $output; my $permcontainer = $containerdir; @@ -2511,9 +2778,9 @@ sub write_bb5_questions { my ($image,$imglink,$url); if ( defined($$settings{$id}{image}) ) { if ( $$settings{$id}{style} eq 'embed' ) { - $image = qq|

|; + $image = qq|

|; } else { - $imglink = qq|
Link to file
|; + $imglink = qq|
Link to file
|; } } if ( defined($$settings{$id}{url}) ) { @@ -2558,9 +2825,9 @@ sub write_bb5_questions { my ($ans_image,$ans_link); if ( defined($$settings{$id}{$$allanswers{$id}[$k]}{image}) ) { if ( $$settings{$id}{$$allanswers{$id}[$k]}{style} eq 'embed' ) { - $ans_image .= qq|

|; + $ans_image .= qq|

|; } else { - $ans_link .= qq|
Link to file
|; + $ans_link .= qq|
Link to file
|; } } $output .= $ans_image.$ans_link.''."\n"; @@ -2811,7 +3078,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 +3110,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#

##g; } if ($$settings{$id}{class} eq 'numerical') { foreach my $numid (@{$$settings{$id}{numids}}) { @@ -2868,8 +3136,10 @@ sub write_webct4_questions { $resourcedata{$symb.'randomize'} = 'yes'; $resourcedata{$symb.'maxfoils'} = 10; if ($context eq 'CSTR') { - $output = qq| + unless ($$settings{$id}{class} eq 'numerical') { + $output = qq| |; + } } $$total{prob} ++; if (exists($$settings{$id}{uri})) { @@ -2930,7 +3200,7 @@ 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::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#(]+)>#$1../../resfiles/$2 />#gi; $$settings{$id}{$list}{$$allanswers{$id}{$list}[$k]}{text} =~ s###g; @@ -3004,7 +3274,7 @@ sub write_webct4_questions { $$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::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#( - + |; } } else { @@ -3067,7 +3337,7 @@ sub write_webct4_questions { 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::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#( |; foreach my $numid (@{$$settings{$id}{numids}}) { 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}}) { my $decnum = $$settings{$id}{$numid}{vars}{$var}{dec}; my $increment = '0.'; @@ -3242,9 +3535,7 @@ sub write_webct4_questions { } $increment .= '1'; } - $formula =~ s/{($var)}/\$$1/g; - $formula =~ s/ln\(?([^\)])\)?/ &log($1) /g; - $formula =~ s/sqrt/\&sqrt/g; + $formula =~ s/{($var)}/(\$$1)/g; $scriptblock .= qq| \$$var=&random($$settings{$id}{$numid}{vars}{$var}{min},$$settings{$id}{$numid}{vars}{$var}{max},$increment); |; @@ -3254,7 +3545,7 @@ sub write_webct4_questions { |; if ($context eq 'CSTR') { - $output = $scriptblock.$output; + $output = "\n".$scriptblock.$output; my $ansformat = ''; my $sigfig = '0,15'; if ($$settings{$id}{$numid}{format} eq 'sig') { @@ -3275,7 +3566,7 @@ sub write_webct4_questions { } my $unitentry = ''; if ($unit ne '') { - $unitentry = 'unit='.$unit; + $unitentry = 'unit="'.$unit.'"'; } $output .= qq| @@ -3332,7 +3623,414 @@ sub test_for_html { } 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| +|; + } + $$total{prob} ++; + $questiontext .= &add_images_links('question',$context,$settings,$id,$dirname,$res); + if ($$settings{$id}{class} eq "Essay") { + if ($context eq 'CSTR') { + $output .= qq|$questiontext + + + +|; + } else { + $resourcedata{$symb.'questiontext'} = $questiontext; + $resourcedata{$symb.'hiddenparts'} = '!essay'; + $resourcedata{$symb.'questiontype'} = 'essay'; + } + } else { + if ($context eq 'CSTR') { + $output .= qq|$questiontext\n|; + } 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| + + +|; + } 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',$context,$settings,$id,$dirname,$res); + $output .= " '."\n"; + $resourcedata{$symb.'text'.$iter} = $answer_text; + } + if ($context eq 'CSTR') { + chomp($output); + $output .= qq| + + + + + + + + + +|; + } + } elsif ($$settings{$id}{class} eq 'Multiple Answer') { + 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<$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',$context,$settings,$id,$dirname,$res); + + $output .= " \n"; + $resourcedata{$symb.'text'.$iter} = $answer_text; + } + if ($context eq 'CSTR') { + chomp($output); + $output .= qq| + + + + + + + + + +|; + } + } elsif ($$settings{$id}{class} eq 'Ordering') { + my @allorder = (); + if ($context eq 'CSTR') { + $output .= qq| + + +|; + } 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',$context,$settings,$id,$dirname,$res); + my $iter = $k+1; + if ($context eq 'CSTR') { + $output .= " ".$answer_text."\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| + + +|; + } 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| + + + + + + + + + + + + +|; + } + } 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| + + + + + + + + + + + +|; + } 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| + + + + + + + + + + + +|; + } + } + } + } elsif ($$settings{$id}{class} eq "Matching") { + my @allmatchers = (); + my %matchtext = (); + if ($context eq 'CSTR') { + $output .= qq| + + + +|; + } 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,$context,$settings,$id,$dirname,$res); + push(@allmatchers,$choice_plaintext); + if ($context eq 'CSTR') { + $output .= qq| + +$choice_text + + |; + } + } + if ($context eq 'CSTR') { + $output .= qq| + +|; + } + 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,$context,$settings,$id,$dirname,$res); + if ($context eq 'CSTR') { + $output .= ' + + '.$answer_text.' + +'; + } 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| + + +|; + } else { + $resourcedata{$symb.'options'} = "('".join("','",@allmatchers)."')"; + } + } + } + if ($context eq 'CSTR') { + + $output .= qq| + + $$settings{$id}{solutionfeedback}{text} + + +|; + 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 $copyfile = $dirname.'/'.$filename; + my $source = "$docroot/$res/webimages/$filename"; + my $fileresult; + if (-e $source) { + $fileresult = &Apache::lonnet::process_coursefile('copy',$cname,$cdom,$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 @@ -3877,5 +4575,59 @@ $linktag } } +sub process_html { + my ($text,$caller,$html_cond,$context,$res,$dirname,$cdom,$cnum,$docroot,$destdir) = @_; + my $pathstart; + if ($context eq 'CSTR') { + $pathstart = '../..'; + } else { + $pathstart = $dirname; + } + 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#]*>#) { + if (&retrieve_image($context,$res,$dirname,$cdom,$cnum,$docroot,$destdir,$1,$2) eq 'ok') { + $$text =~ s#(]*>)#$1$pathstart/resfiles/$res/webimages/$3$4#g; + } + } + $$text =~ s#(]+)/*>#$1 />#gi; + $$text =~ s#
#
#g; + return; +} + +sub add_images_links { + my ($type,$context,$settings,$id,$dirname,$res) = @_; + my ($image,$imglink,$url,$pathstart); + if ($context eq 'CSTR') { + $pathstart = '../..'; + } else { + $pathstart = $dirname; + } + if ((defined($$settings{$id}{$type}{image})) && ($$settings{$id}{$type}{image} ne '')) { + if ( $$settings{$id}{$type}{style} eq 'Inline' ) { + $image = qq|
$$settings{$id}{$type}{label}
|; + } else { + $imglink = qq|
$$settings{$id}{$type}{label}
|; + } + } + if ((defined($$settings{$id}{$type}{link})) && ($$settings{$id}{$type}{link} ne '' )) { + $url = qq|
$$settings{$id}{$type}{linkname}
|; + } + return $image.$imglink.$url; +} + +sub remove_html { + my ($choice_text) = @_; + return $choice_text; +} + + 1; __END__