--- loncom/imspackages/imsprocessor.pm 2005/02/14 22:46:12 1.14
+++ loncom/imspackages/imsprocessor.pm 2005/07/13 19:56:37 1.24
@@ -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;
@@ -51,6 +54,11 @@ sub ims_config {
survey => 'FORM',
);
@{$$cmsmap{angel}{doc}} = ('FILE','PAGE');
+ %{$$cmsmap{webct4}} = (
+ quiz => 'webctquiz',
+ survey => 'webctsurvey',
+ doc => 'webcontent'
+ );
%{$areaname} = (
announce => 'Announcements',
board => 'Discussion Boards',
@@ -90,7 +98,7 @@ sub uploadzip {
my ($context,$tempdir,$source) = @_;
my $fname;
if ($context eq 'DOCS') {
- $fname=$ENV{'form.uploadname.filename'};
+ $fname=$env{'form.uploadname.filename'};
# Replace Windows backslashes by forward slashes
$fname=~s/\\/\//g;
# Get rid of everything but the actual filename
@@ -102,9 +110,9 @@ sub uploadzip {
# See if there is anything left
unless ($fname) { return 'error: no uploaded file'; }
# Save the file
- chomp($ENV{'form.uploadname'});
+ chomp($env{'form.uploadname'});
open(my $fh,'>'.$tempdir.'/'.$fname);
- print $fh $ENV{'form.uploadname'};
+ print $fh $env{'form.uploadname'};
close($fh);
} elsif ($context eq 'CSTR') {
if ($source =~ m/\/([^\/]+)$/) {
@@ -123,14 +131,8 @@ sub expand_zip {
return 'no zip';
}
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 |");
close(OUTPUT);
- %ENV=%oldENV;
- undef(%oldENV);
} else {
return 'nozip';
}
@@ -146,6 +148,7 @@ sub process_manifest {
bb6 => 'organization',
bb5 => 'tableofcontents',
angel => 'organization',
+ webct4 => 'organization',
);
my %contents = ();
my @state = ();
@@ -171,7 +174,7 @@ sub process_manifest {
unless (-e "$tempdir/imsmanifest.xml") {
return 'nomanifest';
- }
+ }
my $xmlfile = $tempdir.'/imsmanifest.xml';
my $p = HTML::Parser->new
@@ -181,24 +184,15 @@ sub process_manifest {
[sub {
my ($tagname, $attr) = @_;
push @state, $tagname;
- my $num = @state - 3;
- my $start = $num;
- my $statestr = '';
- foreach (@state) {
- $statestr .= "$_ ";
- }
+ my $start = @state - 3;
if ( ($state[0] eq "manifest") && ($state[1] eq "organizations") && ($state[2] eq $toc{$cms}) ) {
- my $searchstr = "manifest organizations $toc{$cms}";
- while ($num > 0) {
- $searchstr .= " item";
- $num --;
- }
- if (("@state" eq $searchstr) && (@state > 3)) {
+ if ($state[-1] eq 'item') {
$itm = $attr->{identifier};
- if ($$includeditems{$itm} || $phase ne 'build') {
+ if ($$includeditems{$itm} || $phase ne 'build') {
%{$$items{$itm}} = ();
$$items{$itm}{contentscount} = 0;
- if ($cms eq 'bb5' || $cms eq 'bb6') {
+ @{$$items{$itm}{contents}} = ();
+ if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webct4') {
$$items{$itm}{resnum} = $attr->{identifierref};
if ($cms eq 'bb5') {
$$items{$itm}{title} = $attr->{title};
@@ -252,12 +246,20 @@ sub process_manifest {
$lastitem = $itm;
}
}
+ if ($cms eq 'webct4') {
+ if (($state[-1] eq "webct:properties") && (@state > 4)) {
+ $$items{$itm}{properties} = $attr->{identifierref};
+ }
+ }
} elsif ("@state" eq "manifest resources resource" ) {
$identifier = $attr->{identifier};
if ($$includedres{$identifier} || $phase ne 'build') {
if ($cms eq 'bb5' || $cms eq 'bb6') {
$$resources{$identifier}{file} = $attr->{file};
$$resources{$identifier}{type} = $attr->{type};
+ } elsif ($cms eq 'webct4') {
+ $$resources{$identifier}{type} = $attr->{type};
+ $$resources{$identifier}{file} = $attr->{href};
} elsif ($cms eq 'angel') {
$identifier = substr($identifier,3);
if ($attr->{href} =~ m-^_assoc/$identifier/(.+)$-) {
@@ -268,7 +270,7 @@ sub process_manifest {
}
} elsif ("@state" eq "manifest resources resource file") {
if ($$includedres{$identifier} || $phase ne 'build') {
- if ($cms eq 'bb5' || $cms eq 'bb6') {
+ if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webct4') {
push @{$$hrefs{$identifier}},$attr->{href};
} elsif ($cms eq 'angel') {
if ($attr->{href} =~ m/^_assoc\\$identifier\\(.+)$/) {
@@ -283,11 +285,18 @@ sub process_manifest {
text_h =>
[sub {
my ($text) = @_;
+ if ("@state" eq "manifest metadata lom general title langstring") {
+ $$items{'Top'}{title} = $text;
+ }
if ($state[0] eq "manifest" && $state[1] eq "organizations" && $state[2] eq $toc{$cms} && $state[-1] eq "title") {
if ($$includeditems{$itm} || $phase ne 'build') {
if ($cms eq 'angel' || $cms eq 'bb6') {
$$items{$itm}{title} = $text;
}
+ if ($cms eq 'webct4') {
+ $$items{$itm}{title} = $text;
+ $$items{$itm}{title} =~ s/(<[^>]*>)//g;
+ }
}
}
}, "dtext"],
@@ -353,6 +362,9 @@ sub copy_resources {
%{$$url{$key}} = ();
foreach my $file (@{$$hrefs{$key}}) {
my $source = $tempdir.'/'.$key.'/'.$file;
+ if ($cms eq 'webct4') {
+ $source = $tempdir.'/'.$file;
+ }
my $filename = '';
my $fpath = $timenow.'/resfiles/'.$key.'/';
if ($cms eq 'angel') {
@@ -361,8 +373,19 @@ sub copy_resources {
}
}
$file =~ s-\\-/-g;
- $file = $fpath.$file;
- my $fileresult = &Apache::lonnet::process_coursefile('copy',$crs,$cdom,$chome,$file,$source);
+ my $copyfile = $file;
+ if ($cms eq 'webct4') {
+ if ($file =~ m-/my_files/(.+)$-) {
+ $copyfile = $1;
+ }
+ }
+ unless (($cms eq 'webct4') && ($copyfile =~ m/questionDB\.xml$/ || $copyfile =~ m/quiz_QIZ_\d+\.xml$/ || $copyfile =~ m/properties_QIZ_\d+\.xml$/)) {
+ $copyfile = $fpath.$copyfile;
+ my $fileresult;
+ if (-e $source) {
+ $fileresult = &Apache::lonnet::process_coursefile('copy',$crs,$cdom,$chome,$copyfile,$source);
+ }
+ }
}
}
}
@@ -374,11 +397,10 @@ sub copy_resources {
if (grep/^$key$/,@{$targets}) {
foreach my $file (@{$$hrefs{$key}}) {
$file =~ s-\\-/-g;
- if ( ($cms eq 'angel' && $file ne 'pg'.$key.'.htm') || ($cms eq 'bb5') || ($cms eq 'bb6') ) {
+ if ( ($cms eq 'angel' && $file ne 'pg'.$key.'.htm') || ($cms eq 'bb5') || ($cms eq 'bb6')) {
if (!-e "$destdir/resfiles/$key") {
mkdir("$destdir/resfiles/$key",0770);
}
-
my $filepath = $file;
my $front = '';
while ($filepath =~ m-(\w+)/(.+)-) {
@@ -395,6 +417,26 @@ sub copy_resources {
} elsif ($cms eq 'bb5' || $cms eq 'bb6') {
rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file");
}
+ } elsif ($cms eq 'webct4') {
+ if ($file =~ m-/my_files/(.+)$-) {
+ my $copyfile = $1;
+ if ($copyfile =~ m-^[^/]+/[^/]+-) {
+ my @dirs = split/\//,$copyfile;
+ my $path = "$destdir/resfiles";
+ while (@dirs > 1) {
+ $path .= '/'.$dirs[0];
+ if (!-e "$path") {
+ mkdir("$path",0755);
+ }
+ shift @dirs;
+ }
+ }
+ if (-e "$tempdir/$file") {
+ rename("$tempdir/$file","$destdir/resfiles/$copyfile");
+ }
+ } elsif ($file !~ m-/data/(.+)$-) {
+ &Apache::lonnet::logthis("IMS import error: WebCT4 - file $file is in unexpected location");
+ }
}
}
}
@@ -403,11 +445,14 @@ sub copy_resources {
}
sub process_resinfo {
- my ($cms,$context,$docroot,$destdir,$items,$resources,$targets,$boards,$announcements,$quizzes,$surveys,$pools,$groups,$messages,$timestamp,$boardnum,$resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,$total,$dirname,$seqstem,$resrcfiles,$packages,$hrefs,$pagesfiles,$sequencesfiles) = @_;
+ my ($cms,$context,$docroot,$destdir,$items,$resources,$targets,$boards,$announcements,$quizzes,$surveys,$pools,$groups,$messages,$timestamp,$boardnum,$resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,$total,$dirname,$seqstem,$resrcfiles,$packages,$hrefs,$pagesfiles,$sequencesfiles,$randompicks) = @_;
my $board_id = time;
my $board_count = 0;
+ my $dbparse = 0;
my $announce_handling = 'include';
my $longcrs = '';
+ my %qzdbsettings = ();
+ my %catinfo = ();
if ($crs =~ m/^(\d)(\d)(\d)/) {
$longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
}
@@ -471,15 +516,15 @@ sub process_resinfo {
}
} elsif ($$resources{$key}{type} eq "assessment/x-bb-pool") {
%{$$resinfo{$key}} = ();
- &process_assessment($context,$key,$docroot,'pool',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles);
+ &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") {
%{$$resinfo{$key}} = ();
- &process_assessment($context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles);
+ &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") {
%{$$resinfo{$key}} = ();
- &process_assessment($context,$key,$docroot,'survey',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles);
+ &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;
} elsif ($$resources{$key}{type} eq "assessment/x-bb-group") {
%{$$resinfo{$key}} = ();
@@ -514,6 +559,17 @@ sub process_resinfo {
if (@{$pools}) {
$$items{'Top'}{'contentscount'} ++;
}
+ } elsif ($cms eq 'webct4') {
+ foreach my $key (sort keys %{$resources}) {
+ if (grep/^$key$/,@{$targets}) {
+ if ($$resources{$key}{type} eq "webcontent") {
+ %{$$resinfo{$key}} = ();
+ &webct4_content($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$$resources{$key}{type},$$items{$$resources{$key}{revitm}}{title},$resrcfiles);
+ } elsif ($$resources{$key}{type} eq "webctquiz") {
+ &process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs);
+ }
+ }
+ }
}
$$total{'board'} = $board_count;
@@ -523,7 +579,7 @@ sub process_resinfo {
}
sub build_structure {
- my ($cms,$context,$destdir,$items,$resinfo,$resources,$targets,$hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,$timestamp,$total,$boards,$announcements,$quizzes,$surveys,$pools,$boardnum,$pagesfiles,$seqfiles,$topurls,$topnames,$packages,$includeditems) = @_;
+ my ($cms,$context,$destdir,$items,$resinfo,$resources,$targets,$hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,$timestamp,$total,$boards,$announcements,$quizzes,$surveys,$pools,$boardnum,$pagesfiles,$seqfiles,$topurls,$topnames,$packages,$includeditems,$randompicks) = @_;
my %flag = ();
my %count = ();
my %pagecontents = ();
@@ -582,11 +638,12 @@ sub build_structure {
my $curr_id = 1;
my $resnum = $$items{$key}{resnum};
my $type = $$resources{$resnum}{type};
- if (($cms eq 'angel' && $type eq "FOLDER") || (($cms eq 'bb5' || $cms eq 'bb6') && $$resinfo{$resnum}{'isfolder'} eq "true") && (($type eq "resource/x-bb-document") || ($type eq "resource/x-bb-staffinfo") || ($type eq "resource/x-bb-externallink")) ) {
+ my $contentscount = $$items{$key}{'contentscount'};
+ if (($cms eq 'angel' && $type eq "FOLDER") || (($cms eq 'bb5' || $cms eq 'bb6') && $$resinfo{$resnum}{'isfolder'} eq "true") && (($type eq "resource/x-bb-document") || ($type eq "resource/x-bb-staffinfo") || ($type eq "resource/x-bb-externallink")) || ($cms eq 'webct4' && $contentscount > 0)) {
unless (($cms eq 'bb5') && $key eq 'Top') {
$seqtext{$key} = "|;
+ if (!-e "$destdir/problems") {
+ mkdir("$destdir/problems",0755);
+ }
+ if (!-e "$destdir/problems/$seqname") {
+ mkdir("$destdir/problems/$seqname",0755);
+ }
+ $newdir = "$destdir/problems/$seqname";
+ my $dbcontainerdir;
+ &build_problem_container($cms,$seqname,$destdir,'database',$seqname,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,\@{$$catinfo{$category}{contents}},$udom,$uname,$dirname,\$dbcontainerdir,$cid,$cdom,$cnum,$catinfo,$qzdbsettings);
+ }
+ close($fh);
+ &write_webct4_questions(\@alldbquestids,$context,$qzdbsettings,$dirname,\%alldbanswers,\%alldbchoices,$total,$cid,$cdom,$cnum,$destdir,$catinfo);
+ $$dbparse = 1;
+ }
+ &parse_webct4_assessment($res,$docroot,$$resources{$res}{file},$container,\@allids);
+ &parse_webct4_quizprops($res,$docroot,$$hrefs{$$items{$$resources{$res}{revitm}}{properties}}[0],$container,\%qzparams);
+ if (exists($qzparams{$res}{numpick})) {
+ if ($qzparams{$res}{numpick} < @allids) {
+ $$randompicks{$$resources{$res}{revitm}} = $qzparams{$res}{numpick};
+ $randompickflag = 1;
+ }
+ }
+ }
+ my $dirtitle;
+ unless ($cms eq 'webct4') {
+ $dirtitle = $$settings{'title'};
+ $dirtitle =~ s/\W//g;
+ $dirtitle .= '_'.$res;
+ if (!-e "$destdir/problems") {
+ mkdir("$destdir/problems",0755);
+ }
+ if (!-e "$destdir/problems/$dirtitle") {
+ mkdir("$destdir/problems/$dirtitle",0755);
+ }
+ $newdir = "$destdir/problems/$dirtitle";
+ }
+
+ if ($cms eq 'webct4') {
+ &build_problem_container($cms,$dirtitle,$destdir,$container,$res,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,\@allids,$udom,$uname,$dirname,\$containerdir,$cid,$cdom,$cnum,$catinfo,$qzdbsettings);
+ } 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,$destdir,$res,\%allanswers,\%allchoices,$total,$newdir,$cid,$cdom,$cnum,$docroot);
+ } elsif ($cms eq 'bb6') {
+ &write_bb6_questions(\@allids,$containerdir,$context,$settings,$dirname,$destdir,$res,\%allanswers,\%allchoices,$total,$newdir,$cid,$cdom,$cnum);
+ }
+}
+
+sub build_problem_container {
+ my ($cms,$dirtitle,$destdir,$container,$res,$total,$sequencesfiles,$pagesfiles,$randompickflag,$context,$allids,$udom,$uname,$dirname,$containerdir,$cid,$cdom,$cnum,$catinfo,$settings) = @_;
my $seqdir = "$destdir/sequences";
my $pagedir = "$destdir/pages";
my $curr_id = 0;
my $next_id = 1;
my $fh;
- my $containerdir;
- if ($container eq 'pool') {
- $containerdir = $seqdir.'/'.$res.'.sequence';
+ if ($container eq 'pool' || $randompickflag || $container eq 'database') {
+ $$containerdir = $seqdir.'/'.$res.'.sequence';
if (!-e "$seqdir") {
mkdir("$seqdir",0770);
}
- open($fh,">$containerdir");
+ open($fh,">$$containerdir");
$$total{seq} ++;
push @{$sequencesfiles},$res.'.sequence';
} else {
- $containerdir = $pagedir.'/'.$res.'.page';
+ $$containerdir = $pagedir.'/'.$res.'.page';
if (!-e "$destdir/pages") {
mkdir("$destdir/pages",0770);
}
- open($fh,">$containerdir");
+ open($fh,">$$containerdir");
$$total{page} ++;
push @{$pagesfiles},$res.'.page';
}
print $fh qq||;
close($fh);
+}
+
+sub write_bb5_questions {
+ my ($allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$allanswers,$allchoices,$total,$newdir,$cid,$cdom,$cnum,$docroot) = @_;
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#]*>#) {
+ if (&retrieve_image($context,$res,$dirname,$cdom,$cnum,$docroot,$destdir,$1,$2) eq 'ok') {
+ $$settings{$id}{text} =~ s#(]*>)#$1../../resfiles/$res/webimages/$3$4#g;
+ }
+ }
+ $$settings{$id}{text} =~ s#(]+)/*>#$1 />#gi;
+ $$settings{$id}{text} =~ s#
#
#g;
$qnum ++;
my $output;
my $permcontainer = $containerdir;
@@ -1785,7 +2500,7 @@ sub process_assessment {
$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') {
@@ -1800,7 +2515,7 @@ sub process_assessment {
- $$settings{$id}{feedbackcorr}
+ $$settings{$id}{feedbackcorr}
|;
} else {
@@ -1832,7 +2547,7 @@ sub process_assessment {
$resourcedata{$symb.'questiontext'} .= $image.$imglink.$url;
}
if ($$settings{$id}{class} eq 'QUESTION_MULTIPLECHOICE') {
- my $numfoils = @{$allanswers{$id}};
+ my $numfoils = @{$$allanswers{$id}};
if ($context eq 'CSTR') {
$output .= qq|
@@ -1843,30 +2558,30 @@ sub process_assessment {
$resourcedata{$symb.'questiontype'} = 'radio';
$resourcedata{$symb.'maxfoils'} = $numfoils;
}
- for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
+ for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
my $iter = $k+1;
$output .= "
|;
+ if ( defined($$settings{$id}{$$allanswers{$id}[$k]}{image}) ) {
+ if ( $$settings{$id}{$$allanswers{$id}[$k]}{style} eq 'embed' ) {
+ $ans_image .= qq|
|;
} else {
- $ans_link .= qq|
Link to file
|;
+ $ans_link .= qq|
Link to file
|;
}
}
$output .= $ans_image.$ans_link.''."\n";
@@ -1880,7 +2595,7 @@ sub process_assessment {
|;
}
} elsif ($$settings{$id}{class} eq 'QUESTION_TRUEFALSE') {
- my $numfoils = @{$allanswers{$id}};
+ my $numfoils = @{$$allanswers{$id}};
if ($context eq 'CSTR') {
$output .= qq|
@@ -1891,18 +2606,18 @@ sub process_assessment {
$resourcedata{$symb.'hiddenparts'} = '!radio';
$resourcedata{$symb.'questiontype'} = 'radio';
}
- for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
+ for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
my $iter = $k+1;
$output .= " \n";
- $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$allanswers{$id}[$k]}{text};
+ $output .= "\>".$$settings{$id}{$$allanswers{$id}[$k]}{text}."\n";
+ $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$$allanswers{$id}[$k]}{text};
}
if ($context eq 'CSTR') {
chomp($output);
@@ -1912,7 +2627,7 @@ sub process_assessment {
|;
}
} elsif ($$settings{$id}{class} eq 'QUESTION_MULTIPLEANSWER') {
- my $numfoils = @{$allanswers{$id}};
+ my $numfoils = @{$$allanswers{$id}};
if ($context eq 'CSTR') {
$output .= qq|
@@ -1926,18 +2641,18 @@ sub process_assessment {
$resourcedata{$symb.'questiontype'} = 'option';
$resourcedata{$symb.'maxfoils'} = $numfoils;
}
- for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
+ for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
my $iter = $k+1;
$output .= " \n";
- $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$allanswers{$id}[$k]}{text};
+ $output .= "\>".$$settings{$id}{$$allanswers{$id}[$k]}{text}."\n";
+ $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$$allanswers{$id}[$k]}{text};
}
if ($context eq 'CSTR') {
chomp($output);
@@ -1947,7 +2662,7 @@ sub process_assessment {
|;
}
} elsif ($$settings{$id}{class} eq 'QUESTION_ORDER') {
- my $numfoils = @{$allanswers{$id}};
+ my $numfoils = @{$$allanswers{$id}};
my @allorder = ();
if ($context eq 'CSTR') {
$output .= qq|
@@ -1961,14 +2676,14 @@ sub process_assessment {
$resourcedata{$symb.'questiontype'} = 'option';
$resourcedata{$symb.'maxfoils'} = $numfoils;
}
- for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
+ for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
if ($context eq 'CSTR') {
- $output .= " ".$$settings{$id}{$allanswers{$id}[$k]}{text}."\n";
+ $output .= " ".$$settings{$id}{$$allanswers{$id}[$k]}{text}."\n";
} else {
my $iter = $k+1;
- $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$allanswers{$id}[$k]}{text};
- if (!grep/^$$settings{$id}{$allanswers{$id}[$k]}{order}$/,@allorder) {
- push @allorder, $$settings{$id}{$allanswers{$id}[$k]}{order};
+ $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$$allanswers{$id}[$k]}{text};
+ if (!grep/^$$settings{$id}{$$allanswers{$id}[$k]}{order}$/,@allorder) {
+ push @allorder, $$settings{$id}{$$allanswers{$id}[$k]}{order};
}
}
}
@@ -1987,8 +2702,8 @@ sub process_assessment {
if ($context eq 'DOCS') {
$numerical = 0;
} else {
- for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
- if ($$settings{$id}{$allanswers{$id}[$k]}{text} =~ m/([^\d\.]|\.\.)/) {
+ for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
+ if ($$settings{$id}{$$allanswers{$id}[$k]}{text} =~ m/([^\d\.]|\.\.)/) {
$numerical = 0;
}
}
@@ -1996,18 +2711,18 @@ sub process_assessment {
if ($numerical) {
my $numans;
my $tol;
- if (@{$allanswers{$id}} == 1) {
+ if (@{$$allanswers{$id}} == 1) {
$tol = 5;
- $numans = $$settings{$id}{$allanswers{$id}[0]}{text};
+ $numans = $$settings{$id}{$$allanswers{$id}[0]}{text};
} else {
- my $min = $$settings{$id}{$allanswers{$id}[0]}{text};
- my $max = $$settings{$id}{$allanswers{$id}[0]}{text};
- for (my $k=1; $k<@{$allanswers{$id}}; $k++) {
- if ($$settings{$id}{$allanswers{$id}[$k]}{text} <= $min) {
- $min = $$settings{$id}{$allanswers{$id}[$k]}{text};
+ my $min = $$settings{$id}{$$allanswers{$id}[0]}{text};
+ my $max = $$settings{$id}{$$allanswers{$id}[0]}{text};
+ for (my $k=1; $k<@{$$allanswers{$id}}; $k++) {
+ if ($$settings{$id}{$$allanswers{$id}[$k]}{text} <= $min) {
+ $min = $$settings{$id}{$$allanswers{$id}[$k]}{text};
}
- if ($$settings{$id}{$allanswers{$id}[$k]}{text} >= $max) {
- $max = $$settings{$id}{$allanswers{$id}[$k]}{text};
+ if ($$settings{$id}{$$allanswers{$id}[$k]}{text} >= $max) {
+ $max = $$settings{$id}{$$allanswers{$id}[$k]}{text};
}
}
$numans = ($max + $min)/2;
@@ -2027,23 +2742,23 @@ sub process_assessment {
if ($context eq 'DOCS') {
$resourcedata{$symb.'hiddenparts'} = '!string';
$resourcedata{$symb.'questiontype'} = 'string';
- $resourcedata{$symb.'maxfoils'} = @{$allanswers{$id}};
+ $resourcedata{$symb.'maxfoils'} = @{$$allanswers{$id}};
$resourcedata{$symb.'hiddenparts'} = '!string';
$resourcedata{$symb.'stringtype'} = 'ci';
- $resourcedata{$symb.'stringanswer'} = $$settings{$id}{$allanswers{$id}[0]}{text};
+ $resourcedata{$symb.'stringanswer'} = $$settings{$id}{$$allanswers{$id}[0]}{text};
} else {
- if (@{$allanswers{$id}} == 1) {
+ if (@{$$allanswers{$id}} == 1) {
$output .= qq|
-
+
|;
} else {
my @answertext = ();
- for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
- $$settings{$id}{$allanswers{$id}[$k]}{text} =~ s/\|/\|/g;
- push @answertext, $$settings{$id}{$allanswers{$id}[$k]}{text};
+ for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
+ $$settings{$id}{$$allanswers{$id}[$k]}{text} =~ s/\|/\|/g;
+ push @answertext, $$settings{$id}{$$allanswers{$id}[$k]}{text};
}
my $regexpans = join('|',@answertext);
$regexpans = '/^('.$regexpans.')\b/';
@@ -2070,19 +2785,19 @@ sub process_assessment {
$resourcedata{$symb.'delopt'} = '';
$resourcedata{$symb.'hiddenparts'} = '!option';
$resourcedata{$symb.'questiontype'} = 'option';
- $resourcedata{$symb.'maxfoils'} = @{$allanswers{$id}};
+ $resourcedata{$symb.'maxfoils'} = @{$$allanswers{$id}};
}
- for (my $k=0; $k<@{$allchoices{$id}}; $k++) {
+ for (my $k=0; $k<@{$$allchoices{$id}}; $k++) {
if ($context eq 'CSTR') {
$output .= qq|
--
-$$settings{$id}{$allchoices{$id}[$k]}{text}
+
-
+$$settings{$id}{$$allchoices{$id}[$k]}{text}
|;
} else {
- if (!grep/^$$settings{$id}{$allchoices{$id}[$k]}{text}$/,@allmatchers) {
- push @allmatchers, $$settings{$id}{$allchoices{$id}[$k]}{text};
- $matchtext{$allchoices{$id}[$k]} = $$settings{$id}{$allchoices{$id}[$k]}{text};
+ if (!grep/^$$settings{$id}{$$allchoices{$id}[$k]}{text}$/,@allmatchers) {
+ push @allmatchers, $$settings{$id}{$$allchoices{$id}[$k]}{text};
+ $matchtext{$$allchoices{$id}[$k]} = $$settings{$id}{$$allchoices{$id}[$k]}{text};
}
}
}
@@ -2091,17 +2806,17 @@ sub process_assessment {
|;
}
- for (my $k=0; $k<@{$allanswers{$id}}; $k++) {
+ for (my $k=0; $k<@{$$allanswers{$id}}; $k++) {
if ($context eq 'CSTR') {
$output .= qq|
-
- $$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') {
@@ -2117,7 +2832,526 @@ 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} = &HTML::Entities::decode($$settings{$id}{text});
+ $$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#
##;
+# $$settings{$id}{text} =~ s###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|
+
+|;
+ }
+ } else {
+ $resourcedata{$symb.'options'} = "('".join("','",@allmatch)."')";
+ }
+ } elsif ($$settings{$id}{class} eq 'string') {
+ my $labelnum = 0;
+ foreach my $str_id (@{$$settings{$id}{str}}) {
+ foreach my $label (@{$$settings{$id}{$str_id}{labels}}) {
+ $labelnum ++;
+ my $numerical = 1;
+ if ($context eq 'DOCS') {
+ $numerical = 0;
+ } else {
+ for (my $i=0; $i<@{$$settings{$id}{strings}{$label}}; $i++) {
+ $$settings{$id}{strings}{$label}[$i] =~ s/^\s+//;
+ $$settings{$id}{strings}{$label}[$i] =~ s/\s+$//;
+ if ($$settings{$id}{strings}{$label}[$i] =~ m/([^-\d\.]|\.\.)/) {
+ $numerical = 0;
+ }
+ }
+ }
+ if ($numerical) {
+ my $numans;
+ my $tol;
+ if (@{$$settings{$id}{strings}{$label}} == 1) {
+ $tol = '5%';
+ $numans = $$settings{$id}{strings}{$label}[0];
+ } else {
+ my $min = $$settings{$id}{strings}{$label}[0];
+ my $max = $$settings{$id}{strings}{$label}[0];
+ for (my $k=1; $k<@{$$settings{$id}{strings}{$label}}; $k++) {
+ if ($$settings{$id}{strings}{$label}[$k] <= $min) {
+ $min = $$settings{$id}{strings}{$label}[$k];
+ }
+ if ($$settings{$id}{strings}{$label}[$k] >= $max) {
+ $max = $$settings{$id}{strings}{$label}[$k];
+ }
+ }
+ $numans = ($max + $min)/2;
+ if ($numans == 0) {
+ my $dev = abs($max - $numans);
+ if (abs($numans - $min) > $dev) {
+ $dev = abs($numans - $min);
+ }
+ $tol = $dev;
+ } else {
+ $tol = 100*($max - $min)/($numans*2);
+ $tol .= '%';
+ }
+ }
+ if ($context eq 'CSTR') {
+ if (@{$$settings{$id}{str}} > 1) {
+ $output .= qq|
+$labelnum.
+|;
+ }
+ $output .= qq|
+
+
+
+
+
+
+|;
+ }
+ } else {
+ if ($context eq 'DOCS') {
+ $resourcedata{$symb.'hiddenparts'} = '!string';
+ $resourcedata{$symb.'questiontype'} = 'string';
+ $resourcedata{$symb.'maxfoils'} = @{$$allanswers{$id}{strings}{$label}};
+ $resourcedata{$symb.'hiddenparts'} = '!string';
+ if ($$settings{$id}{$label}{case} eq "No") {
+ $resourcedata{$symb.'stringtype'} = 'ci';
+ } elsif ($$settings{$id}{$label}{case} eq "Yes") {
+ $resourcedata{$symb.'stringtype'} = 'cs';
+ }
+ $resourcedata{$symb.'stringanswer'} = $$settings{$id}{strings}{$label}[0];
+ } else {
+ if (@{$$settings{$id}{str}} > 1) { $output .= qq|
+$labelnum.
+|;
+ }
+ if (@{$$settings{$id}{strings}{$label}} == 1) {
+ my $casetype;
+ if ($$settings{$id}{$label}{case} eq "No") {
+ $casetype = 'ci';
+ } elsif ($$settings{$id}{$label}{case} eq "Yes") {
+ $casetype = 'cs';
+ }
+ $output .= qq|
+
+
+
+
+
+|;
+ } else {
+ my @answertext = ();
+ for (my $k=0; $k<@{$$settings{$id}{strings}{$label}}; $k++) {
+ $$settings{$id}{strings}{$label}[$k] =~ s/\|/\|/g;
+ push @answertext, $$settings{$id}{strings}{$label}[$k];
+ }
+ my $regexpans = join('|',@answertext);
+ $regexpans = '/^('.$regexpans.')\b/';
+ $output .= qq|
+
+
+
+
+
+|;
+ }
+ }
+ }
+ }
+ }
+ } 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|
+
+|;
+ if ($context eq 'CSTR') {
+ $output = "\n".$scriptblock.$output;
+ my $ansformat = '';
+ my $sigfig = '0,15';
+ if ($$settings{$id}{$numid}{format} eq 'sig') {
+ $sigfig = $$settings{$id}{$numid}{digits}.','.$$settings{$id}{$numid}{digits};
+ } elsif ($$settings{$id}{$numid}{format} eq 'dec') {
+ $ansformat = $$settings{$id}{$numid}{digits}.'f';
+ }
+ if ($ansformat) {
+ $ansformat = 'format="'.$ansformat.'"';
+ }
+ my $tolerance = $$settings{$id}{$numid}{tolerance};
+ if ($$settings{$id}{$numid}{toltype} eq 'percent') {
+ $tolerance .= '%';
+ }
+ my $unit = '';
+ foreach my $unitid (@{$$settings{$id}{$numid}{units}}) {
+ $unit .= $$settings{$id}{$numid}{$unitid}{text};
+ }
+ my $unitentry = '';
+ if ($unit ne '') {
+ $unitentry = 'unit='.$unit;
+ }
+ $output .= qq|
+
+
+
+
+
+|;
+ }
+ }
+ }
+ }
+ if ($context eq 'CSTR') {
+ my $catid = $$settings{$id}{category};
+ my $probdir = $$catinfo{$catid}{title}.'_'.$catid;
+ $probdir =~ s/\s/_/g;
+ $probdir =~ s/\W//g;
+ if (!-e "$destdir/problems/$probdir") {
+ mkdir("$destdir/problems/$probdir",0755);
+ }
+ $output .= qq|
+|;
+ my $title = $$settings{$id}{title};
+ $title =~ s/\s/_/g;
+ $title =~ s/\W//g;
+ $title .= '_'.$id;
+ open(PROB,">:utf8", "$destdir/problems/$probdir/$title.problem");
print PROB $output;
close PROB;
} else {
@@ -2128,6 +3362,69 @@ sub process_assessment {
}
}
+sub test_for_html {
+ my ($source) = @_;
+ my @tags = ();
+ my $p = HTML::Parser->new
+ (
+ xml_mode => 1,
+ start_h =>
+ [sub {
+ my ($tagname) = @_;
+ push @tags, $tagname;
+ }, "tagname"],
+ );
+ $p->parse($source);
+ $p->eof;
+ return length(@tags);
+}
+
+sub write_bb6_questions {
+ my ($allids,$containerdir,$context,$settings,$dirname,$destdir,$res,$allanswers,$allchoices) = @_;
+}
+
+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
sub process_announce {
my ($res,$docroot,$destdir,$settings,$globalresref,$seqstem,$resrcfiles) = @_;
@@ -2222,8 +3519,7 @@ sub process_content {
my $xmlfile = $docroot.'/'.$res.".dat";
my $destresdir = $destdir;
if ($context eq 'CSTR') {
-# $destresdir =~ s|/home/$user/public_html/|/res/$dom/$user/|;
- $destresdir =~ s|/home/$user/public_html/|/priv/$user/|;
+ $destresdir =~ s|/home/$user/public_html/|/res/$dom/$user/|;
} elsif ($context eq 'DOCS') {
$destresdir =~ s|^/home/httpd/html/userfiles|/uploaded|;
}
@@ -2643,5 +3939,33 @@ sub angel_content {
close(FILE);
}
+# ---------------------------------------------------------------- WebCT content
+sub webct4_content {
+ my ($res,$docroot,$destdir,$settings,$dom,$user,$type,$title,$resrcfiles) = @_;
+ if (!open(FILE,">$destdir/resfiles/$res.html")) {
+ &Apache::lonnet::logthis("IMS import error: Cannot open file - $destdir/resfiles/$res.html - $!");
+ } else {
+ push(@{$resrcfiles}, "$res.html");
+ my $linktag = '';
+ if (defined($$settings{url})) {
+ $linktag = qq|$title|;
+ } else {
+ $linktag .= qq|>$$settings{url}|;
+ }
+ }
+ print FILE qq|
+
+$title
+
+
+$linktag
+
+|;
+ close(FILE);
+ }
+}
+
1;
__END__