--- loncom/imspackages/imsprocessor.pm 2005/02/21 23:47:46 1.15
+++ loncom/imspackages/imsprocessor.pm 2005/05/03 18:38:37 1.20
@@ -24,6 +24,8 @@
package Apache::imsprocessor;
use Apache::lonnet;
+use LWP::UserAgent;
+use HTTP::Request::Common;
use LONCAPA::Configuration;
use strict;
@@ -95,7 +97,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
@@ -107,9 +109,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/\/([^\/]+)$/) {
@@ -128,14 +130,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';
}
@@ -177,7 +173,7 @@ sub process_manifest {
unless (-e "$tempdir/imsmanifest.xml") {
return 'nomanifest';
- }
+ }
my $xmlfile = $tempdir.'/imsmanifest.xml';
my $p = HTML::Parser->new
@@ -187,23 +183,14 @@ 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;
+ @{$$items{$itm}{contents}} = ();
if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webct4') {
$$items{$itm}{resnum} = $attr->{identifierref};
if ($cms eq 'bb5') {
@@ -258,12 +245,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' || $cms eq 'webct4') {
+ 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/(.+)$-) {
@@ -379,11 +374,11 @@ sub copy_resources {
$file =~ s-\\-/-g;
my $copyfile = $file;
if ($cms eq 'webct4') {
- if ($file =~ m-/([^/]+)$-) {
+ if ($file =~ m-/my_files/(.+)$-) {
$copyfile = $1;
}
}
- unless (($cms eq 'webct4') && ($copyfile eq 'questionDB.xml' || $copyfile =~ m/^quiz_QIZ_\d+\.xml$/)) {
+ unless (($cms eq 'webct4') && ($copyfile =~ m/questionDB\.xml$/ || $copyfile =~ m/quiz_QIZ_\d+\.xml$/ || $copyfile =~ m/properties_QIZ_\d+\.xml$/)) {
$copyfile = $fpath.$copyfile;
my $fileresult;
if (-e $source) {
@@ -422,14 +417,24 @@ sub copy_resources {
rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file");
}
} elsif ($cms eq 'webct4') {
- if (!-e "$destdir/resfiles/$key") {
- mkdir("$destdir/resfiles/$key",0770);
- }
- if ($file =~ m-/([^/]+)$-) {
+ if ($file =~ m-/my_files/(.+)$-) {
my $copyfile = $1;
- unless ($copyfile eq 'questionDB.xml' || $copyfile =~ m/^quiz_QIZ_\d+\.xml$/) {
- rename("$tempdir/$file","$destdir/resfiles/$key/$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");
}
}
}
@@ -445,6 +450,8 @@ sub process_resinfo {
my $dbparse = 0;
my $announce_handling = 'include';
my $longcrs = '';
+ my %qzdbsettings = ();
+ my %catinfo = ();
if ($crs =~ m/^(\d)(\d)(\d)/) {
$longcrs = $1.'/'.$2.'/'.$3.'/'.$crs;
}
@@ -508,15 +515,15 @@ sub process_resinfo {
}
} elsif ($$resources{$key}{type} eq "assessment/x-bb-pool") {
%{$$resinfo{$key}} = ();
- &process_assessment($cms,$context,$key,$docroot,'pool',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse);
+ &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($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse);
+ &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($cms,$context,$key,$docroot,'survey',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse);
+ &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}} = ();
@@ -556,11 +563,9 @@ sub process_resinfo {
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);
+ &webct4_content($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$$resources{$key}{type},$$items{$$resources{$key}{revitm}}{title},$resrcfiles);
} elsif ($$resources{$key}{type} eq "webctquiz") {
-# &webct4_assessment($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$$resources{$key}{type},$$items{$$resources{$key}{revitm}}{title},$resrcfiles);
- &process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse);
-
+ &process_assessment($cms,$context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles,$randompicks,\$dbparse,$resources,$items,\%catinfo,\%qzdbsettings,$hrefs);
}
}
}
@@ -634,7 +639,6 @@ sub build_structure {
my $type = $$resources{$resnum}{type};
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)) {
- print STDERR "$key is identified as a folder has $contentscount\n";
unless (($cms eq 'bb5') && $key eq 'Top') {
$seqtext{$key} = "
##;
+# $$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') {
+ $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::lonxml::chtmlclean($$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::lonxml::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 $scriptblock = qq|
+
+|;
+ if ($context eq 'CSTR') {
+ $output = $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 {
+# put %resourcedata;
+ my $reply=&Apache::lonnet::cput
+ ('resourcedata',\%resourcedata,$cdom,$cnum);
+ }
+ }
}
+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,$res,$allanswers,$allchoices) = @_;
+ 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
@@ -3234,11 +3943,5 @@ $linktag
}
}
-# ---------------------------------------------------------------- WebCT assessments
-sub webct4_assessment {
- my ($res,$docroot,$destdir,$settings,$dom,$user,$type,$title,$resrcfiles) = @_;
- print STDERR "webct assessment detected - $res, $docroot, $destdir, $type,$title\n";
-}
-
1;
__END__