--- loncom/imspackages/imsprocessor.pm 2004/03/20 00:45:16 1.5 +++ loncom/imspackages/imsprocessor.pm 2005/02/14 22:46:12 1.14 @@ -1,3 +1,26 @@ +# Copyright Michigan State University Board of Trustees +# +# This file is part of the LearningOnline Network with CAPA (LON-CAPA). +# +# LON-CAPA is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# LON-CAPA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LON-CAPA; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# /home/httpd/html/adm/gpl.txt +# +# http://www.lon-capa.org/ +# + package Apache::imsprocessor; use Apache::lonnet; @@ -18,7 +41,8 @@ sub ims_config { survey => 'assessment/x-bb-survey', users => 'course/x-bb-user', ); - + %{$$cmsmap{bb6}} = %{$$cmsmap{bb5}}; + $$cmsmap{bb6}{conference} = 'resource/x-bb-conference'; %{$$cmsmap{angel}} = ( board => 'BOARD', extlink => 'LINK', @@ -26,10 +50,7 @@ sub ims_config { quiz => 'QUIZ', survey => 'FORM', ); - @{$$cmsmap{angel}{doc}} = ('FILE','PAGE'); - - %{$areaname} = ( announce => 'Announcements', board => 'Discussion Boards', @@ -41,7 +62,6 @@ sub ims_config { survey => 'Surveys', users => 'Enrollment', ); - } sub create_tempdir { @@ -99,12 +119,18 @@ sub uploadzip { sub expand_zip { my ($tempdir,$filename) = @_; my $zipfile = "$tempdir/$filename"; + if (!-e "$zipfile") { + 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 |"); - while () { - print "$_
"; - } close(OUTPUT); + %ENV=%oldENV; + undef(%oldENV); } else { return 'nozip'; } @@ -115,8 +141,9 @@ sub expand_zip { } sub process_manifest { - my ($cms,$tempdir,$resources,$items,$hrefs,$resinfo) = @_; + my ($cms,$tempdir,$resources,$items,$hrefs,$resinfo,$phase,$includedres,$includeditems) = @_; my %toc = ( + bb6 => 'organization', bb5 => 'tableofcontents', angel => 'organization', ); @@ -136,11 +163,12 @@ sub process_manifest { if ($cms eq 'angel') { $$resources{'toplevel'}{type} = "FOLDER"; - } elsif ($cms eq 'bb5') { + } elsif ($cms eq 'bb5' || $cms eq 'bb6') { $$resources{'toplevel'}{type} = 'resource/x-bb-document'; + } else { + $$resources{'toplevel'}{type} = 'webcontent'; } - unless (-e "$tempdir/imsmanifest.xml") { return 'nomanifest'; } @@ -166,92 +194,100 @@ sub process_manifest { $num --; } if (("@state" eq $searchstr) && (@state > 3)) { - $itm = $attr->{identifier}; - %{$$items{$itm}} = (); - $$items{$itm}{contentscount} = 0; - if ($cms eq 'bb5') { - $$items{$itm}{resnum} = $attr->{identifierref}; - $$items{$itm}{title} = $attr->{title}; - } elsif ($cms eq 'angel') { - if ($attr->{identifierref} =~ m/^res(.+)$/) { - $$items{$itm}{resnum} = $1; - } - } - unless (defined(%{$$resources{$$items{$itm}{resnum}}}) ) { - %{$$resources{$$items{$itm}{resnum}}} = (); - } - $$resources{$$items{$itm}{resnum}}{revitm} = $itm; - - if ($start > @seq) { - unless ($lastitem eq '') { - push @seq, $lastitem; - unless ( defined($contents{$seq[-1]}) ) { - @{$contents{$seq[-1]}} = (); + $itm = $attr->{identifier}; + if ($$includeditems{$itm} || $phase ne 'build') { + %{$$items{$itm}} = (); + $$items{$itm}{contentscount} = 0; + if ($cms eq 'bb5' || $cms eq 'bb6') { + $$items{$itm}{resnum} = $attr->{identifierref}; + if ($cms eq 'bb5') { + $$items{$itm}{title} = $attr->{title}; + } + } elsif ($cms eq 'angel') { + if ($attr->{identifierref} =~ m/^res(.+)$/) { + $$items{$itm}{resnum} = $1; } - push @{$contents{$seq[-1]}},$itm; - $$items{$itm}{parentseq} = $seq[-1]; } - } - elsif ($start < @seq) { - my $diff = @seq - $start; - while ($diff > 0) { - pop @seq; - $diff --; + unless (defined(%{$$resources{$$items{$itm}{resnum}}}) ) { + %{$$resources{$$items{$itm}{resnum}}} = (); } - if (@seq) { + $$resources{$$items{$itm}{resnum}}{revitm} = $itm; + if ($start > @seq) { + unless ($lastitem eq '') { + push @seq, $lastitem; + unless ( defined($contents{$seq[-1]}) ) { + @{$contents{$seq[-1]}} = (); + } + push @{$contents{$seq[-1]}},$itm; + $$items{$itm}{parentseq} = $seq[-1]; + } + } elsif ($start < @seq) { + my $diff = @seq - $start; + while ($diff > 0) { + pop @seq; + $diff --; + } + if (@seq) { + push @{$contents{$seq[-1]}}, $itm; + } + } else { push @{$contents{$seq[-1]}}, $itm; } - } else { - push @{$contents{$seq[-1]}}, $itm; - } - my $path; - if (@seq > 1) { - $path = join(',',@seq); - } elsif (@seq > 0) { - $path = $seq[0]; - } - $$items{$itm}{filepath} = $path; - if ($cms eq 'bb5') { - if ($$items{$itm}{filepath} eq 'Top') { - $$items{$itm}{resnum} = $itm; - $$resources{$$items{$itm}{resnum}}{type} = 'resource/x-bb-document'; - $$resources{$$items{$itm}{resnum}}{revitm} = $itm; - $$resinfo{$$items{$itm}{resnum}}{'isfolder'} = 'true'; + my $path; + if (@seq > 1) { + $path = join(',',@seq); + } elsif (@seq > 0) { + $path = $seq[0]; + } + $$items{$itm}{filepath} = $path; + if ($cms eq 'bb5' || $cms eq 'bb6') { + if ($$items{$itm}{filepath} eq 'Top') { + $$items{$itm}{resnum} = $itm; + $$resources{$$items{$itm}{resnum}}{type} = 'resource/x-bb-document'; + $$resources{$$items{$itm}{resnum}}{revitm} = $itm; + $$resinfo{$$items{$itm}{resnum}}{'isfolder'} = 'true'; + } } + $$items{$seq[-1]}{contentscount} ++; + $lastitem = $itm; } - $$items{$seq[-1]}{contentscount} ++; - $lastitem = $itm; } } elsif ("@state" eq "manifest resources resource" ) { $identifier = $attr->{identifier}; - if ($cms eq 'bb5') { - $$resources{$identifier}{file} = $attr->{file}; - $$resources{$identifier}{type} = $attr->{type}; - } elsif ($cms eq 'angel') { - $identifier = substr($identifier,3); - if ($attr->{href} =~ m-^_assoc/$identifier/(.+)$-) { - $$resources{$identifier}{file} = $1; - } + 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 'angel') { + $identifier = substr($identifier,3); + if ($attr->{href} =~ m-^_assoc/$identifier/(.+)$-) { + $$resources{$identifier}{file} = $1; + } + } + @{$$hrefs{$identifier}} = (); } - @{$$hrefs{$identifier}} = (); } elsif ("@state" eq "manifest resources resource file") { - if ($cms eq 'bb5') { - push @{$$hrefs{$identifier}},$attr->{href}; - } elsif ($cms eq 'angel') { - if ($attr->{href} =~ m/^_assoc\\$identifier\\(.+)$/) { - push @{$$hrefs{$identifier}},$1; - } elsif ($attr->{href} =~ m/^Icons\\icon(\w+)\.gif/) { - $$resources{$identifier}{type} = $1; - } + if ($$includedres{$identifier} || $phase ne 'build') { + if ($cms eq 'bb5' || $cms eq 'bb6') { + push @{$$hrefs{$identifier}},$attr->{href}; + } elsif ($cms eq 'angel') { + if ($attr->{href} =~ m/^_assoc\\$identifier\\(.+)$/) { + push @{$$hrefs{$identifier}},$1; + } elsif ($attr->{href} =~ m/^Icons\\icon(\w+)\.gif/) { + $$resources{$identifier}{type} = $1; + } + } } } }, "tagname, attr"], text_h => [sub { my ($text) = @_; - if ($state[0] eq "manifest" && $state[1] eq "organizations" && $state[2] eq "organization" && $state[-1] eq "title") { - if ($cms eq 'angel') { - $$items{$itm}{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; + } } } }, "dtext"], @@ -270,6 +306,35 @@ sub process_manifest { return 'ok' ; } +sub get_imports { + my ($includeditems,$items,$resources,$importareas,$itm) = @_; + if (exists($$items{$itm}{resnum})) { + if ($$importareas{$$resources{$$items{$itm}{resnum}}{type}}) { + unless (exists($$includeditems{$itm})) { + $$includeditems{$itm} = 1; + } + } + } + if ($$items{$itm}{contentscount} > 0) { + foreach my $child (@{$$items{$itm}{contents}}) { + &get_imports($includeditems,$items,$resources,$importareas,$child); + } + } +} + +sub get_parents { + my ($includeditems,$items,$itm) = @_; + my @pathitems = (); + if ($$items{$itm}{filepath} =~ m/,/) { + @pathitems = split/,/,$$items{$itm}{filepath}; + } else { + $pathitems[0] = $$items{$itm}{filepath}; + } + foreach (@pathitems) { + $$includeditems{$_} = 1; + } +} + sub target_resources { my ($resources,$oktypes,$targets) = @_; foreach my $key (keys %{$resources}) { @@ -306,28 +371,30 @@ sub copy_resources { mkdir("$destdir/resfiles",0770); } foreach my $key (sort keys %{$hrefs}) { - foreach my $file (@{$$hrefs{$key}}) { - $file =~ s-\\-/-g; - if ( ($cms eq 'angel' && $file ne 'pg'.$key.'.htm') || ($cms eq 'bb5') ) { - if (!-e "$destdir/resfiles/$key") { - mkdir("$destdir/resfiles/$key",0770); - } - - my $filepath = $file; - my $front = ''; - while ($filepath =~ m-(\w+)/(.+)-) { - $front .= $1.'/'; - $filepath = $2; - my $fulldir = "$destdir/resfiles/$key/$front"; - chop($fulldir); - if (!-e "$fulldir") { - mkdir("$fulldir",0770); + 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 (!-e "$destdir/resfiles/$key") { + mkdir("$destdir/resfiles/$key",0770); + } + + my $filepath = $file; + my $front = ''; + while ($filepath =~ m-(\w+)/(.+)-) { + $front .= $1.'/'; + $filepath = $2; + my $fulldir = "$destdir/resfiles/$key/$front"; + chop($fulldir); + if (!-e "$fulldir") { + mkdir("$fulldir",0770); + } + } + if ($cms eq 'angel') { + rename("$tempdir/_assoc/$key/$file","$destdir/resfiles/$key/$file"); + } elsif ($cms eq 'bb5' || $cms eq 'bb6') { + rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file"); } - } - if ($cms eq 'angel') { - rename("$tempdir/_assoc/$key/$file","$destdir/resfiles/$key/$file"); - } elsif ($cms eq 'bb5') { - rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file"); } } } @@ -335,38 +402,8 @@ sub copy_resources { } } -sub process_coursefile { - my ($crs,$cdom,$chome,$file,$source)=@_; - my $fetchresult = ''; - my $fpath = ''; - my $fname = $file; - ($fpath,$fname) = ($file =~ m/^(.*)\/([^\/])$/); - $fpath=$cdom.'/'.$crs.'/'.$fpath; - my $filepath=$Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles'; - unless ($fpath eq '') { - my @parts=split(/\//,$fpath); - foreach my $part (@parts) { - $filepath.= '/'.$part; - if ((-e $filepath)!=1) { - mkdir($filepath,0777); - } - } - } - if ($source eq '') { - $fetchresult eq 'no source file provided'; - } else { - my $destination = $filepath.'/'.$fname; - rename($source,$destination); - $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$cdom.'/'.$crs.'/'.$file,$chome); - unless ($fetchresult eq 'ok') { - &Apache::lonnet::logthis('Failed to transfer '.$cdom.'/'.$crs.'/'.$fname.' to host '.$chome.': '.$fetchresult); - } - } - return $fetchresult; -} - sub process_resinfo { - my ($cms,$docroot,$destdir,$items,$resources,$boards,$announcements,$quizzes,$surveys,$groups,$messages,$timestamp,$boardnum,$resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,$total,$dirname,$seqstem,$resrcfiles) = @_; + 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 $board_id = time; my $board_count = 0; my $announce_handling = 'include'; @@ -374,9 +411,15 @@ sub process_resinfo { if ($crs =~ m/^(\d)(\d)(\d)/) { $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs; } + if ($context eq 'CSTR') { + if (!-e "$destdir/resfiles") { + mkdir("$destdir/resfiles",0770); + } + } if ($cms eq 'angel') { my $currboard = ''; foreach my $key (sort keys %{$resources}) { + if (grep/^$key$/,@{$targets}) { if ($$resources{$key}{type} eq "BOARD") { push @{$boards}, $key; $$boardnum{$$resources{$key}{revitm}} = $board_count; @@ -401,13 +444,15 @@ sub process_resinfo { } elsif ($$resources{$key}{type} eq "DROPBOX") { %{$$resinfo{$key}} = (); } + } } - } elsif ($cms eq 'bb5') { + } elsif ($cms eq 'bb5' || $cms eq 'bb6') { foreach my $key (sort keys %{$resources}) { + if (grep/^$key$/,@{$targets}) { if ($$resources{$key}{type} eq "resource/x-bb-document") { unless ($$items{$$resources{$key}{revitm}}{filepath} eq 'Top') { %{$$resinfo{$key}} = (); - &process_content($key,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$resrcfiles); + &process_content($cms,$key,$context,$docroot,$destdir,\%{$$resinfo{$key}},$udom,$uname,$resrcfiles,$packages,$hrefs); } } elsif ($$resources{$key}{type} eq "resource/x-bb-staffinfo") { %{$$resinfo{$key}} = (); @@ -426,14 +471,15 @@ sub process_resinfo { } } elsif ($$resources{$key}{type} eq "assessment/x-bb-pool") { %{$$resinfo{$key}} = (); - &process_assessment($key,$docroot,'pool',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname); + &process_assessment($context,$key,$docroot,'pool',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles); + push @{$pools}, $key; } elsif ($$resources{$key}{type} eq "assessment/x-bb-quiz") { %{$$resinfo{$key}} = (); - &process_assessment($key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname); + &process_assessment($context,$key,$docroot,'quiz',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles); push @{$quizzes}, $key; } elsif ($$resources{$key}{type} eq "assessment/x-bb-survey") { %{$$resinfo{$key}} = (); - &process_assessment($key,$docroot,'survey',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname); + &process_assessment($context,$key,$docroot,'survey',$dirname,$destdir,\%{$$resinfo{$key}},$total,$udom,$uname,$pagesfiles,$sequencesfiles); push @{$surveys}, $key; } elsif ($$resources{$key}{type} eq "assessment/x-bb-group") { %{$$resinfo{$key}} = (); @@ -451,6 +497,7 @@ sub process_resinfo { &process_announce($key,$docroot,$destdir,\%{$$resinfo{$key}},$resinfo,$seqstem,$resrcfiles); } } + } } if (@{$announcements}) { $$items{'Top'}{'contentscount'} ++; @@ -463,22 +510,26 @@ sub process_resinfo { } if (@{$surveys}) { $$items{'Top'}{'contentscount'} ++; - + } + if (@{$pools}) { + $$items{'Top'}{'contentscount'} ++; } } $$total{'board'} = $board_count; $$total{'quiz'} = @{$quizzes}; $$total{'surv'} = @{$surveys}; + $$total{'pool'} = @{$pools}; } sub build_structure { - my ($cms,$context,$destdir,$items,$resinfo,$resources,$hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,$timestamp,$total,$boards,$announcements,$quizzes,$surveys,$boardnum,$pagesfiles,$seqfiles,$topurls,$topnames) = @_; + 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 %flag = (); my %count = (); my %pagecontents = (); my %seqtext = (); my $topnum = 0; + my $topspecials = @$announcements + @$boards + @$quizzes + @$surveys + @$pools; if (!-e "$destdir") { mkdir("$destdir",0755); @@ -510,6 +561,7 @@ sub build_structure { } foreach my $key (sort keys %{$items}) { + if ($$includeditems{$key}) { %{$flag{$key}} = ( page => 0, seq => 0, @@ -530,21 +582,33 @@ 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' && $$resinfo{$resnum}{'isfolder'} eq "true") && (($type eq "resource/x-bb-document") || ($type eq "resource/x-bb-staffinfo") || ($type eq "resource/x-bb-externallink")) ) { - unless ($cms eq 'bb5' && $key eq 'Top') { + 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")) ) { + unless (($cms eq 'bb5') && $key eq 'Top') { $seqtext{$key} = "\n"; } if ($$items{$key}{contentscount} == 0) { - $seqtext{$key} .= qq| + if ($key eq 'Top') { + unless ($topspecials) { + $seqtext{$key} .= qq| + +\n|; + } + } else { + $seqtext{$key} .= qq| \n|; + } } else { my $contcount = @{$$items{$key}{contents}}; my $contitem = $$items{$key}{contents}[0]; my $res = $$items{$contitem}{resnum}; my $type = $$resources{$res}{type}; my $title = $$items{$contitem}{title}; - $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$resinfo,$contitem,$uname,$cdom); + my $packageflag = 0; + if (grep/^$res$/,@{$packages}) { + $packageflag = 1; + } + $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag); unless ($flag{$key}{page} == 1) { $seqtext{$key} .= qq| - +|; + if ($key eq 'Top') { + unless ($topspecials) { + $seqtext{$key} .= qq| \n|; + } + } else { + $seqtext{$key} .= qq| +\n|; + } } else { if ($contcount > 2 ) { for (my $i=1; $i<$contcount-1; $i++) { my $contitem = $$items{$key}{contents}[$i]; my $res = $$items{$contitem}{resnum}; my $type = $$resources{$res}{type}; - my $title = $$items{$contitem}{title}; - $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$resinfo,$contitem,$uname,$cdom); + my $title = $$items{$contitem}{title}; + my $packageflag = 0; + if (grep/^$res$/,@{$packages}) { + $packageflag = 1; + } + $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag); unless ($flag{$key}{page} == 1) { $seqtext{$key} .= qq|> @@ -587,8 +663,11 @@ sub build_structure { my $res = $$items{$contitem}{resnum}; my $type = $$resources{$res}{type}; my $title = $$items{$contitem}{title}; - - $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$resinfo,$contitem,$uname,$cdom); + my $packageflag = 0; + if (grep/^$res$/,@{$packages}) { + $packageflag = 1; + } + $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag); if ($flag{$key}{page}) { if ($count{$key}{seq} + $count{$key}{page} + $count{$key}{board} + $count{$key}{file} +1 == 1) { $seqtext{$key} .= qq|> @@ -610,11 +689,11 @@ sub build_structure { $curr_id ++; $next_id ++; $seqtext{$key} .= qq|> -\n|; +\n|; } } } - unless ($cms eq 'bb5' && $key eq 'Top') { + unless (($cms eq 'bb5') && $key eq 'Top') { $seqtext{$key} .= "\n"; open(LOCFILE,">$destdir/sequences/$key.sequence"); print LOCFILE $seqtext{$key}; @@ -625,10 +704,11 @@ sub build_structure { $$total{page} += $count{$key}{page}; } $$total{seq} += $count{$key}{seq}; + } } $topnum += ($count{'Top'}{page} + $count{'Top'}{seq}); - if ($cms eq 'bb5') { + if ($cms eq 'bb5' || $cms eq 'bb6') { if (@{$announcements} > 0) { &process_specials($context,'announcements',$announcements,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames); } @@ -641,7 +721,9 @@ sub build_structure { if (@{$surveys} > 0) { &process_specials($context,'surveys',$surveys,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames); } - + if (@{$pools} > 0) { + &process_specials($context,'pools',$pools,\$topnum,$$items{'Top'}{contentscount},$destdir,$udom,$uname,$cdom,$crs,$timenow,$newdir,$timestamp,$resinfo,\$seqtext{'Top'},$pagesfiles,$seqfiles,$topurls,$topnames); + } $seqtext{'Top'} .= "\n"; open(TOPFILE,">$destdir/sequences/Top.sequence"); print TOPFILE $seqtext{'Top'}; @@ -651,7 +733,7 @@ sub build_structure { my $filestem; if ($context eq 'DOCS') { - $filestem = "/uploaded/$cdom/$crs"; + $filestem = "/uploaded/$cdom/$crs/$timenow"; } elsif ($context eq 'CSTR') { $filestem = "/res/$udom/$uname/$newdir"; } @@ -659,24 +741,44 @@ sub build_structure { foreach my $key (sort keys %pagecontents) { for (my $i=0; $i<@{$pagecontents{$key}}; $i++) { my $filename = $destdir.'/pages/'.$key.'_'.$i.'.page'; + my $resource = "$filestem/resfiles/$$items{$pagecontents{$key}[$i][0]}{resnum}.html"; + my $res = $$items{$pagecontents{$key}[$i][0]}{resnum}; + my $resource = $filestem.'/resfiles/'.$res.'.html'; + if (grep/^$res$/,@{$packages}) { + $resource = $filestem.'/resfiles/'.$res.'./index.html'; # should be entry_point + } open(PAGEFILE,">$filename"); print PAGEFILE qq| - + \n|; if (@{$pagecontents{$key}[$i]} == 1) { print PAGEFILE qq|\n|; } elsif (@{$pagecontents{$key}[$i]} == 2) { - print PAGEFILE qq|\n|; + my $res = $$items{$pagecontents{$key}[$i][1]}{resnum}; + my $resource = $filestem.'/resfiles/'.$res.'.html'; + if (grep/^$res$/,@{$packages}) { + $resource = $filestem.'/resfiles/'.$res.'./index.html'; # should be entry_point + } + print PAGEFILE qq|\n|; } else { for (my $j=1; $j<@{$pagecontents{$key}[$i]}-1; $j++) { my $curr_id = $j+1; my $next_id = $j+2; - my $resource = $filestem.'/resfiles/'.$$items{$pagecontents{$key}[$i][$j]}{resnum}.'.html'; + my $res = $$items{$pagecontents{$key}[$i][$j]}{resnum}; + my $resource = $filestem.'/resfiles/'.$res.'.html'; + if (grep/^$res$/,@{$packages}) { + $resource = $filestem.'/resfiles/'.$res.'./index.html'; # entry_point + } print PAGEFILE qq| \n|; } my $final_id = @{$pagecontents{$key}[$i]}; - print PAGEFILE qq|\n|; + my $res = $$items{$pagecontents{$key}[$i][-1]}{resnum}; + my $resource = $filestem.'/resfiles/'.$res.'.html'; + if (grep/^$res$/,@{$packages}) { + $resource = $filestem.'/resfiles/'.$res.'./index.html'; # entry_point + } + print PAGEFILE qq|\n|; } print PAGEFILE ""; close(PAGEFILE); @@ -686,9 +788,9 @@ sub build_structure { } sub make_structure { - my ($cms,$key,$srcstem,$flag,$count,$timestamp,$boardnum,$hrefs,$pagecontents,$res,$type,$resinfo,$contitem,$uname,$cdom) = @_; + my ($cms,$key,$srcstem,$flag,$count,$timestamp,$boardnum,$hrefs,$pagecontents,$res,$type,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag) = @_; my $src =''; - if (($cms eq 'angel' && $type eq 'FOLDER') || ($cms eq 'bb5' && ($$resinfo{$res}{'isfolder'} eq 'true') || ($key eq 'Top')) ) { + if (($cms eq 'angel' && $type eq 'FOLDER') || (($cms eq 'bb5' || $cms eq 'bb6') && ($$resinfo{$res}{'isfolder'} eq 'true') || ($key eq 'Top')) ) { $src = $srcstem.'/sequences/'.$contitem.'.sequence'; $$flag{$key}{page} = 0; $$flag{$key}{seq} = 1; @@ -719,13 +821,21 @@ sub make_structure { @{$$pagecontents{$key}[$$count{$key}{page}]} = ("$contitem"); $$flag{$key}{seq} = 0; } - } elsif ($cms eq 'bb5') { + } elsif ($cms eq 'bb5' || $cms eq 'bb6') { if ($$flag{$key}{page}) { push @{$$pagecontents{$key}[$$count{$key}{page}]},$contitem; } else { - $$count{$key}{page} ++; - $src = $srcstem.'/pages/'.$key.'_'.$$count{$key}{page}.'.page'; - @{$$pagecontents{$key}[$$count{$key}{page}]} = ("$contitem"); + if ($contcount == 1) { + if ($packageflag) { + $src = $srcstem.'/resfiles/'.$res.'/index.html'; # Needs to be entry point + } else { + $src = $srcstem.'/resfiles/'.$res.'.html'; + } + } else { + $$count{$key}{page} ++; + $src = $srcstem.'/pages/'.$key.'_'.$$count{$key}{page}.'.page'; + @{$$pagecontents{$key}[$$count{$key}{page}]} = ("$contitem"); + } $$flag{$key}{seq} = 0; } } @@ -750,12 +860,14 @@ sub process_specials { quizzes => 'quizzes', surveys => 'surveys', announcements => 'announcements', + pools => 'pools' ); my %seqtitles = ( boards => 'Course Bulletin Boards', quizzes => 'Course Quizzes', surveys => 'Course Surveys', announcements => 'Course Announcements', + pools => 'Course Question Pools' ); $$topnum ++; @@ -797,6 +909,8 @@ sub process_specials { $specialsrc = "/adm/$udom/$uname/$$timestamp[0]/bulletinboard"; } elsif ($type eq 'announcements') { $specialsrc = "$seqstem/resfiles/$$specials[0].html"; + } elsif ($type eq 'pools') { + $specialsrc = "$seqstem/sequences/$$specials[0].sequence"; } else { $specialsrc = "$seqstem/pages/$$specials[0].page"; } @@ -846,13 +960,13 @@ sub process_user { [sub { my ($tagname, $attr) = @_; push @state, $tagname; - if (@state eq "USERS USER") { + if ("@state" eq "USERS USER") { $userid = $attr->{value}; %{$$settings{$userid}} = (); @{$$settings{$userid}{links}} = (); - } elsif (@state eq "USERS USER LOGINID") { + } elsif ("@state" eq "USERS USER LOGINID") { $$settings{$userid}{loginid} = $attr->{value}; - } elsif (@state eq "USERS USER PASSPHRASE") { + } elsif ("@state" eq "USERS USER PASSPHRASE") { $$settings{$userid}{passphrase} = $attr->{value}; } elsif ("@state" eq "USERS USER STUDENTID" ) { $$settings{$userid}{studentid} = $attr->{value}; @@ -890,7 +1004,7 @@ sub process_user { end_h => [sub { my ($tagname) = @_; - if (@state eq "USERS USER") { + if ("@state" eq "USERS USER") { $linknum = 0; } pop @state; @@ -927,14 +1041,14 @@ sub process_group { [sub { my ($tagname, $attr) = @_; push @state, $tagname; - if (@state eq "GROUPS GROUP") { + if ("@state" eq "GROUPS GROUP") { $grp = $attr->{id}; } - if (@state eq "GROUPS GROUP TITLE") { + if ("@state" eq "GROUPS GROUP TITLE") { $$settings{$grp}{title} = $attr->{value}; - } elsif (@state eq "GROUPS GROUP FLAGS ISAVAILABLE") { + } elsif ("@state" eq "GROUPS GROUP FLAGS ISAVAILABLE") { $$settings{$grp}{isavailable} = $attr->{value}; - } elsif (@state eq "GROUPS GROUP FLAGS HASCHATROOM") { + } elsif ("@state" eq "GROUPS GROUP FLAGS HASCHATROOM") { $$settings{$grp}{chat} = $attr->{value}; } elsif ("@state" eq "GROUPS GROUP FLAGS HASDISCUSSIONBOARD") { $$settings{$grp}{discussion} = $attr->{value}; @@ -979,11 +1093,11 @@ sub process_staff { [sub { my ($tagname, $attr) = @_; push @state, $tagname; - if (@state eq "STAFFINFO TITLE") { + if ("@state" eq "STAFFINFO TITLE") { $$settings{title} = $attr->{value}; - } elsif (@state eq "STAFFINFO BIOGRAPHY TEXTCOLOR") { + } elsif ("@state" eq "STAFFINFO BIOGRAPHY TEXTCOLOR") { $$settings{textcolor} = $attr->{value}; - } elsif (@state eq "STAFFINFO BIOGRAPHY FLAGS ISHTML") { + } elsif ("@state" eq "STAFFINFO BIOGRAPHY FLAGS ISHTML") { $$settings{ishtml} = $attr->{value}; } elsif ("@state" eq "STAFFINFO FLAGS ISAVAILABLE" ) { $$settings{isavailable} = $attr->{value}; @@ -1156,11 +1270,11 @@ sub process_link { [sub { my ($tagname, $attr) = @_; push @state, $tagname; - if (@state eq "EXTERNALLINK TITLE") { + if ("@state" eq "EXTERNALLINK TITLE") { $$settings{title} = $attr->{value}; - } elsif (@state eq "EXTERNALLINK TEXTCOLOR") { + } elsif ("@state" eq "EXTERNALLINK TEXTCOLOR") { $$settings{textcolor} = $attr->{value}; - } elsif (@state eq "EXTERNALLINK DESCRIPTION FLAGS ISHTML") { + } elsif ("@state" eq "EXTERNALLINK DESCRIPTION FLAGS ISHTML") { $$settings{ishtml} = $attr->{value}; } elsif ("@state" eq "EXTERNALLINK FLAGS ISAVAILABLE" ) { $$settings{isavailable} = $attr->{value}; @@ -1171,7 +1285,7 @@ sub process_link { } elsif ("@state" eq "EXTERNALLINK POSITION" ) { $$settings{position} = $attr->{value}; } elsif ("@state" eq "EXTERNALLINK URL" ) { - $$settings{url} = $attr->{value}; + $$settings{url} = $attr->{value}; } }, "tagname, attr"], text_h => @@ -1437,17 +1551,13 @@ sub addposting { } # ---------------------------------------------------------------- Process Blackboard Assessments - pools, quizzes, surveys sub process_assessment { - my ($res,$docroot,$container,$dirname,$destdir,$settings,$total,$udom,$uname) = @_; + my ($context,$res,$docroot,$container,$dirname,$destdir,$settings,$total,$udom,$uname,$pagesfiles,$sequencesfiles) = @_; my $xmlfile = $docroot.'/'.$res.".dat"; # print "XML file is $xmlfile\n"; my @state = (); my @allids = (); my %allanswers = (); my %allchoices = (); - my $resdir = ''; - if ($docroot =~ m|public_html/(.+)$|) { - $resdir = $1; - } my $id; # the current question ID my $answer_id; # the current answer ID my %toptag = ( pool => 'POOL', @@ -1493,9 +1603,7 @@ sub process_assessment { } if ("@state" eq "$toptag{$container} QUESTIONLIST QUESTION") { $id = $attr->{id}; - unless ($container eq 'pool') { - push @allids, $id; - } + push @allids, $id; %{$$settings{$id}} = (); @{$allanswers{$id}} = (); $$settings{$id}{class} = $attr->{class}; @@ -1595,46 +1703,99 @@ sub process_assessment { my $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); } my $newdir = "$destdir/problems/$dirtitle"; + my $seqdir = "$destdir/sequences"; my $pagedir = "$destdir/pages"; my $curr_id = 0; my $next_id = 1; - unless ($container eq 'pool') { - open(PAGEFILE,">$pagedir/$res.page"); - print PAGEFILE qq| -|; - $$total{page} ++; - print PAGEFILE qq||; - if (@allids == 1) { - print PAGEFILE qq| + my $fh; + my $containerdir; + if ($container eq 'pool') { + $containerdir = $seqdir.'/'.$res.'.sequence'; + if (!-e "$seqdir") { + mkdir("$seqdir",0770); + } + open($fh,">$containerdir"); + $$total{seq} ++; + push @{$sequencesfiles},$res.'.sequence'; + } else { + $containerdir = $pagedir.'/'.$res.'.page'; + if (!-e "$destdir/pages") { + mkdir("$destdir/pages",0770); + } + open($fh,">$containerdir"); + $$total{page} ++; + push @{$pagesfiles},$res.'.page'; + } + print $fh qq| +|; + my $probsrc = "/res/lib/templates/simpleproblem.problem"; + my ($cid,$cdom,$cnum); + if ($context eq 'DOCS') { + $cid = $ENV{'request.course.id'}; + ($cdom,$cnum) = split/_/,$cid; + } + if ($context eq 'CSTR') { + $probsrc="/res/$udom/$uname/$dirname/problems/$dirtitle/$allids[0].problem"; + } + print $fh qq||; + if (@allids == 1) { + print $fh qq| \n|; - } else { - for (my $j=1; $j<@allids; $j++) { - $curr_id = $j; - $next_id = $curr_id + 1; - print PAGEFILE qq| + } else { + for (my $j=1; $j<@allids; $j++) { + my $qntitle = $j; + while (length($qntitle) <4) { + $qntitle = '0'.$qntitle; + } + $curr_id = $j; + $next_id = $curr_id + 1; + if ($context eq 'CSTR') { + $probsrc = "/res/$udom/$uname/$dirname/problems/$dirtitle/$allids[$j].problem"; + } + print $fh qq| -\n|; - } else { - print PAGEFILE qq|>|; - } +\n|; + } else { + print $fh qq|>|; } } - print PAGEFILE qq||; - close(PAGEFILE); } + print $fh qq||; + close($fh); + my $qnum = 0; foreach my $id (@allids) { - my $output = qq| + $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} ++; if ($$settings{$id}{class} eq "QUESTION_ESSAY") { - $output .= qq|$$settings{$id}{text} + if ($context eq 'CSTR') { + $output .= qq|$$settings{$id}{text} @@ -1642,112 +1803,194 @@ sub process_assessment { $$settings{$id}{feedbackcorr} |; + } else { + $resourcedata{$symb.'questiontext'} = $$settings{$id}{text}; + $resourcedata{$symb.'hiddenparts'} = '!essay'; + $resourcedata{$symb.'questiontype'} = 'essay'; + } } else { - $output .= qq|$$settings{$id}{text}\n|; - if ( defined($$settings{$id}{image}) ) { + if ($context eq 'CSTR') { + $output .= qq|$$settings{$id}{text}\n|; + } else { + $resourcedata{$symb.'questiontext'} = $$settings{$id}{text}; + } + my ($image,$imglink,$url); + if ( defined($$settings{$id}{image}) ) { if ( $$settings{$id}{style} eq 'embed' ) { - $output .= qq|

|; + $image = qq|

|; } else { - $output .= qq|
Link to file
|; + $imglink = qq|
Link to file
|; } } if ( defined($$settings{$id}{url}) ) { - $output .= qq|
$$settings{$id}{name}
|; + $url = qq|
$$settings{$id}{name}
|; + } + if ($context eq 'CSTR') { + $output .= $image.$imglink.$url.' +'; + } else { + $resourcedata{$symb.'questiontext'} .= $image.$imglink.$url; } - $output .= qq| -|; if ($$settings{$id}{class} eq 'QUESTION_MULTIPLECHOICE') { my $numfoils = @{$allanswers{$id}}; - $output .= qq| + 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}}; $k++) { + my $iter = $k+1; $output .= "
|; + $ans_image .= qq|

|; } else { - $output .= qq|
Link to file
|; + $ans_link .= qq|
Link to file
|; } } - $output .= qq|
\n|; + $output .= $ans_image.$ans_link.''."\n"; + $resourcedata{$symb.'text'.$iter} .= $ans_image.$ans_link; } - chomp($output); - $output .= qq| + if ($context eq 'CSTR') { + chomp($output); + $output .= qq|
|; + } } elsif ($$settings{$id}{class} eq 'QUESTION_TRUEFALSE') { my $numfoils = @{$allanswers{$id}}; - $output .= qq| + if ($context eq 'CSTR') { + $output .= qq| |; + } else { + $resourcedata{$symb.'maxfoils'} = $numfoils; + $resourcedata{$symb.'hiddenparts'} = '!radio'; + $resourcedata{$symb.'questiontype'} = 'radio'; + } for (my $k=0; $k<@{$allanswers{$id}}; $k++) { + my $iter = $k+1; $output .= " \n"; + $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$allanswers{$id}[$k]}{text}; } - chomp($output); - $output .= qq| + if ($context eq 'CSTR') { + chomp($output); + $output .= qq| |; + } } elsif ($$settings{$id}{class} eq 'QUESTION_MULTIPLEANSWER') { my $numfoils = @{$allanswers{$id}}; - $output .= qq| + 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}}; $k++) { + my $iter = $k+1; $output .= " \n"; + $resourcedata{$symb.'text'.$iter} = $$settings{$id}{$allanswers{$id}[$k]}{text}; } - chomp($output); - $output .= qq| + if ($context eq 'CSTR') { + chomp($output); + $output .= qq| |; + } } elsif ($$settings{$id}{class} eq 'QUESTION_ORDER') { my $numfoils = @{$allanswers{$id}}; - $output .= qq| + 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<@{$allanswers{$id}}; $k++) { - $output .= " ".$$settings{$id}{$allanswers{$id}[$k]}{text}."\n"; + if ($context eq 'CSTR') { + $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}; + } + } } - chomp($output); - $output .= qq| + if ($context eq 'CSTR') { + chomp($output); + $output .= qq| |; + } else { + @allorder = sort {$a <=> $b} @allorder; + $resourcedata{$symb.'options'} = "('".join("','",@allorder)."')"; + } } elsif ($$settings{$id}{class} eq 'QUESTION_FILLINBLANK') { my $numerical = 1; - for (my $k=0; $k<@{$allanswers{$id}}; $k++) { - if ($$settings{$id}{$allanswers{$id}[$k]}{text} =~ m/([^\d\.]|\.\.)/) { - $numerical = 0; + if ($context eq 'DOCS') { + $numerical = 0; + } else { + for (my $k=0; $k<@{$allanswers{$id}}; $k++) { + if ($$settings{$id}{$allanswers{$id}[$k]}{text} =~ m/([^\d\.]|\.\.)/) { + $numerical = 0; + } } } if ($numerical) { @@ -1770,7 +2013,8 @@ sub process_assessment { $numans = ($max + $min)/2; $tol = 100*($max - $min)/($numans*2); } - $output .= qq| + if ($context eq 'CSTR') { + $output .= qq| |; + } } else { - if (@{$allanswers{$id}} == 1) { - $output .= qq| + if ($context eq 'DOCS') { + $resourcedata{$symb.'hiddenparts'} = '!string'; + $resourcedata{$symb.'questiontype'} = 'string'; + $resourcedata{$symb.'maxfoils'} = @{$allanswers{$id}}; + $resourcedata{$symb.'hiddenparts'} = '!string'; + $resourcedata{$symb.'stringtype'} = 'ci'; + $resourcedata{$symb.'stringanswer'} = $$settings{$id}{$allanswers{$id}[0]}{text}; + } else { + 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}; - } - my $regexpans = join('|',@answertext); - $regexpans = '/^('.$regexpans.')\b/'; - $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}; + } + my $regexpans = join('|',@answertext); + $regexpans = '/^('.$regexpans.')\b/'; + $output .= qq| |; - } + } + } } } elsif ($$settings{$id}{class} eq "QUESTION_MATCH") { - $output .= qq| + 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'} = @{$allanswers{$id}}; + } for (my $k=0; $k<@{$allchoices{$id}}; $k++) { - $output .= qq| + if ($context eq 'CSTR') { + $output .= qq| $$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}; + } + } } - $output .= qq| + if ($context eq 'CSTR') { + $output .= qq| |; + } for (my $k=0; $k<@{$allanswers{$id}}; $k++) { - $output .= qq| + if ($context eq 'CSTR') { + $output .= qq| $$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}; + } } - $output .= qq| + if ($context eq 'CSTR') { + $output .= qq| |; + } else { + $resourcedata{$symb.'options'} = "('".join("','",@allmatchers)."')"; + } } } - $output .= qq|
+ if ($context eq 'CSTR') { + $output .= qq|
|; - open(PROB,">$newdir/$id.problem"); - print PROB $output; - close PROB; + open(PROB,">$newdir/$id.problem"); + print PROB $output; + close PROB; + } else { +# put %resourcedata; + my $reply=&Apache::lonnet::cput + ('resourcedata',\%resourcedata,$cdom,$cnum); + } } } @@ -1856,7 +2145,7 @@ sub process_announce { if ("@state" eq "ANNOUNCEMENT TITLE") { $$settings{title} = $attr->{value}; $$settings{startassessment} = (); - } elsif (@state eq "ANNOUNCEMENT DESCRIPTION FLAGS ISHTML") { + } elsif ("@state" eq "ANNOUNCEMENT DESCRIPTION FLAGS ISHTML") { $$settings{ishtml} = $attr->{value}; } elsif ("@state" eq "ANNOUNCEMENT DESCRIPTION FLAGS ISNEWLINELITERAL" ) { $$settings{isnewline} = $attr->{value}; @@ -1929,10 +2218,21 @@ $$settings{text} # ---------------------------------------------------------------- Process Blackboard Content sub process_content { - my ($res,$docroot,$destdir,$settings,$dom,$user,$resrcfiles) = @_; + my ($cms,$res,$context,$docroot,$destdir,$settings,$dom,$user,$resrcfiles,$packages,$hrefs) = @_; my $xmlfile = $docroot.'/'.$res.".dat"; my $destresdir = $destdir; - $destresdir =~ s|/home/$user/public_html/|/res/$dom/$user/|; + if ($context eq 'CSTR') { +# $destresdir =~ s|/home/$user/public_html/|/res/$dom/$user/|; + $destresdir =~ s|/home/$user/public_html/|/priv/$user/|; + } elsif ($context eq 'DOCS') { + $destresdir =~ s|^/home/httpd/html/userfiles|/uploaded|; + } + my $filetag = ''; + if ($cms eq 'bb5') { + $filetag = 'FILEREF'; + } elsif ($cms eq 'bb6') { + $filetag = 'FILE'; + } my $filecount = 0; my @allrelfiles = (); my @state; @@ -1944,37 +2244,41 @@ sub process_content { [sub { my ($tagname, $attr) = @_; push @state, $tagname; - if (@state eq "CONTENT MAINDATA") { + if ("@state" eq "CONTENT ") { %{$$settings{maindata}} = (); - } elsif (@state eq "CONTENT MAINDATA TEXTCOLOR") { + } elsif ("@state" eq "CONTENT TITLECOLOR") { + $$settings{titlecolor} = $attr->{value}; + } elsif ("@state" eq "CONTENT MAINDATA TEXTCOLOR") { $$settings{maindata}{color} = $attr->{value}; - } elsif (@state eq "CONTENT MAINDATA FLAGS ISHTML") { + } elsif ("@state" eq "CONTENT MAINDATA FLAGS ISHTML") { $$settings{maindata}{ishtml} = $attr->{value}; - } elsif (@state eq "CONTENT MAINDATA FLAGS ISNEWLINELITERAL") { + } elsif ("@state" eq "CONTENT MAINDATA FLAGS ISNEWLINELITERAL") { $$settings{maindata}{isnewline} = $attr->{value}; + } elsif ("@state" eq "CONTENT BODY TYPE") { + $$settings{maindata}{bodytype} = $attr->{value}; } elsif ("@state" eq "CONTENT FLAGS ISAVAILABLE" ) { $$settings{isavailable} = $attr->{value}; } elsif ("@state" eq "CONTENT FLAGS ISFOLDER" ) { $$settings{isfolder} = $attr->{value}; } elsif ("@state" eq "CONTENT FLAGS LAUNCHINNEWWINDOW" ) { $$settings{newwindow} = $attr->{value}; - } elsif ("@state" eq "CONTENT FILES FILEREF") { + } elsif ("@state" eq "CONTENT FILES $filetag") { %{$$settings{files}[$filecount]} = (); %{$$settings{files}[$filecount]{registry}} = (); } elsif ("@state" eq "CONTENT FILES FILEREF RELFILE" ) { $$settings{files}[$filecount]{'relfile'} = $attr->{value}; push @allrelfiles, $attr->{value}; - } elsif ("@state" eq "CONTENT FILES FILEREF MIMETYPE") { + } elsif ("@state" eq "CONTENT FILES $filetag MIMETYPE") { $$settings{files}[$filecount]{mimetype} = $attr->{value}; - } elsif ("@state" eq "CONTENT FILES FILEREF CONTENTTYPE") { + } elsif ("@state" eq "CONTENT FILES $filetag CONTENTTYPE") { $$settings{files}[$filecount]{contenttype} = $attr->{value}; - } elsif ("@state" eq "CONTENT FILES FILEREF FILEACTION") { + } elsif ("@state" eq "CONTENT FILES $filetag FILEACTION") { $$settings{files}[$filecount]{fileaction} = $attr->{value}; - } elsif ("@state" eq "CONTENT FILES FILEREF PACKAGEPARENT") { + } elsif ("@state" eq "CONTENT FILES $filetag PACKAGEPARENT") { $$settings{files}[$filecount]{packageparent} = $attr->{value}; - } elsif ("@state" eq "CONTENT FILES FILEREF LINKNAME") { + } elsif ("@state" eq "CONTENT FILES $filetag LINKNAME") { $$settings{files}[$filecount]{linkname} = $attr->{value}; - } elsif ("@state" eq "CONTENT FILES FILEREF REGISTRY REGISTRYENTRY") { + } elsif ("@state" eq "CONTENT FILES $filetag REGISTRY REGISTRYENTRY") { my $key = $attr->{key}; $$settings{files}[$filecount]{registry}{$key} = $attr->{value}; } @@ -1984,16 +2288,19 @@ sub process_content { my ($text) = @_; if ("@state" eq "CONTENT TITLE") { $$settings{title} = $text; - } elsif ("@state" eq "CONTENT MAINDATA TEXT") { + } elsif ( ("@state" eq "CONTENT MAINDATA TEXT") || ("@state" eq "CONTENT BODY TEXT") ) { $$settings{maindata}{text} = $text; - } elsif ("@state" eq "CONTENT FILES FILEREF REFTEXT") { + } elsif ("@state" eq "CONTENT FILES $filetag REFTEXT") { $$settings{files}[$filecount]{reftext} = $text; + } elsif ("@state" eq "CONTENT FILES FILE NAME" ) { + $$settings{files}[$filecount]{'relfile'} = $text; + push @allrelfiles, $text; } }, "dtext"], end_h => [sub { my ($tagname) = @_; - if ("@state" eq "CONTENT FILES FILEREF") { + if ("@state" eq "CONTENT FILES $filetag") { $filecount ++; } pop @state; @@ -2039,10 +2346,8 @@ sub process_content { } } else { my $filename=$$settings{files}[$filecount]{'relfile'}; -# print "File is $filename\n"; my $newfilename="$destresdir/resfiles/$res/$$settings{files}[$filecount]{relfile}"; -# print "New filename is $newfilename\n"; - $$settings{maindata}{text} =~ s#(src|SRC|value)="$filename"#$1="$newfilename"#g; + $$settings{maindata}{text} =~ s#(src|SRC|value)=("|")$filename("|")#$1="$newfilename"#g; } } elsif ($$settings{files}[$filecount]{fileaction} eq 'link') { unless (($$settings{files}[$filecount]{packageparent} ne '') && (grep/^$$settings{files}[$filecount]{packageparent}$/,@{$$settings{files}}) ) { @@ -2055,8 +2360,28 @@ sub process_content { } $linktag .= qq|>$$settings{files}[$filecount]{linkname}
\n|; } - } elsif ($$settings{files}[$filecount]{fileaction} eq 'package') { -# print "Found a package\n"; + } elsif ( ($$settings{files}[$filecount]{fileaction} eq 'PACKAGE') || ($$settings{files}[$filecount]{fileaction} eq 'package') ) { + my $open_package = ''; + if ($$settings{files}[$filecount]{'relfile'} =~ m|\.zip$|i) { + $open_package = &expand_zip("$docroot/$res",$$settings{files}[$filecount]{'relfile'}); + } + if ($open_package eq 'ok') { + opendir(DIR,"$docroot/$res"); + my @dircontents = grep(!/^\./,readdir(DIR)); + closedir(DIR); + push @{$resrcfiles}, @dircontents; + @{$$hrefs{$res}} = @dircontents; + push @{$packages}, $res; + } + } elsif ( ($$settings{files}[$filecount]{fileaction} eq 'BROKEN_IMAGE') && ($cms eq 'bb6') ) { + my $filename=$$settings{files}[$filecount]{'relfile'}; + my $newfilename="$destresdir/resfiles/$res/$$settings{files}[$filecount]{relfile}"; + $$settings{maindata}{text} =~ s#(src|SRC|value)=("|")$filename("|")#$1="$newfilename"#g; + } elsif ( ($$settings{files}[$filecount]{fileaction} eq 'LINK') && ($cms eq 'bb6') ) { + my $filename=$$settings{files}[$filecount]{'relfile'}; + my $newfilename="$destresdir/resfiles/$res/$$settings{files}[$filecount]{relfile}"; + my $filetitle = $$settings{files}[$filecount]{'linkname'}; + $$settings{maindata}{text} = ''.$filetitle.'

'. $$settings{maindata}{text}; } } } @@ -2064,37 +2389,52 @@ sub process_content { $fontcol = qq||; } if (defined($$settings{maindata}{text})) { + if ($$settings{maindata}{bodytype} eq "S") { + $$settings{maindata}{text} =~ s#\n#
#g; + } if ($$settings{maindata}{ishtml} eq "false") { if ($$settings{maindata}{isnewline} eq "true") { $$settings{maindata}{text} =~ s#\n#
#g; } } else { - $$settings{maindata}{text} = &HTML::Entities::decode($$settings{maindata}{text}); +# $$settings{maindata}{text} = &HTML::Entities::decode($$settings{maindata}{text}); } } - open(FILE,">$destdir/resfiles/$res.html"); - push @{$resrcfiles}, "$res.html"; - print FILE qq| + 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 $htmldoc = 0; +# if ($$settings{maindata}{text} =~ m-<(html|HTML)>.+<\\(html|HTML)-) { + if ($$settings{maindata}{text} =~ m-<(html|HTML)>-) { + $htmldoc = 1; + } + unless ($htmldoc) { + print FILE qq| $$settings{title} $fontcol |; - unless ($$settings{title} eq '') { - print FILE qq|$$settings{title}

\n|; - } - print FILE qq| + } + unless ($$settings{title} eq '') { + print FILE qq|$$settings{title}

\n|; + } + print FILE qq| $$settings{maindata}{text} $linktag|; - if (defined($$settings{maindata}{textcolor})) { - print FILE qq|
|; - } - print FILE qq| + unless ($htmldoc) { + if (defined($$settings{maindata}{textcolor})) { + print FILE qq||; + } + print FILE qq| |; - close(FILE); + } + close(FILE); + } } @@ -2139,7 +2479,6 @@ sub process_angelboards { my $msgcount = 0; my $putresult = &Apache::lonnet::put($boardname,\%boardinfo,$cdom,$crs); -# print STDERR "putresult is $putresult for $boardname $cdom $crs\n"; if ($db_handling eq 'importall') { foreach my $msg_id (@{$$messages{$$boards[$i]}}) { $msgcount ++;