--- loncom/imspackages/imsprocessor.pm 2006/04/15 16:44:56 1.40 +++ loncom/imspackages/imsprocessor.pm 2008/08/23 17:47:44 1.42 @@ -25,6 +25,7 @@ package Apache::imsprocessor; use Apache::lonnet; use Apache::loncleanup; +use Apache::lonlocal; use LWP::UserAgent; use HTTP::Request::Common; use LONCAPA::Configuration; @@ -75,7 +76,7 @@ sub ims_config { survey => 'webctsurvey', doc => 'webcontent' ); - %{$areaname} = ( + %{$areaname} = &Apache::lonlocal::texthash ( announce => 'Announcements', board => 'Discussion Boards', doc => 'Documents, pages, and folders', @@ -308,7 +309,6 @@ sub parse_manifest { if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4' || $cms eq 'webctvista4') { push @{$$hrefs{$identifier}},$attr->{href}; - if ($$resources{$identifier}{type} eq 'webct.manifest') { my $manifestfile = $tempdir.'/'.$attr->{href}; @@ -466,10 +466,14 @@ sub copy_resources { mkdir("$fulldir",0770); } } + my $renameres; if ($cms eq 'angel') { - rename("$tempdir/_assoc/$key/$file","$destdir/resfiles/$key/$file"); + $renameres = rename("$tempdir/_assoc/$key/$file","$destdir/resfiles/$key/$file"); } elsif ($cms eq 'bb5' || $cms eq 'bb6') { - rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file"); + $renameres = rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file"); + } + if (!$renameres) { + &Apache::lonnet::logthis("IMS import error: $cms - renaming failed for file $file"); } } elsif ($cms eq 'webctce4') { if ($file =~ m-/my_files/(.+)$-) { @@ -486,7 +490,10 @@ sub copy_resources { } } if (-e "$tempdir/$file") { - rename("$tempdir/$file","$destdir/resfiles/$copyfile"); + my $renameres = rename("$tempdir/$file","$destdir/resfiles/$copyfile"); + if (!$renameres) { + &Apache::lonnet::logthis("IMS import error: WebCT4 - renaming failed for file $file"); + } } } elsif ($file !~ m-/data/(.+)$-) { &Apache::lonnet::logthis("IMS import error: WebCT4 - file $file is in unexpected location"); @@ -735,7 +742,11 @@ sub build_structure { my $curr_id = 1; my $resnum = $$items{$key}{resnum}; my $type = $$resources{$resnum}{type}; - my $contentscount = $$items{$key}{'contentscount'}; + my $contentscount = $$items{$key}{'contentscount'}; + my $seqtitle = $$items{$key}{'title'}; + $seqtitle =~ s|/+|_|g; + $seqtitle =~ s/\s+/_/g; + $seqtitle .= '_'.$key; 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 'webctce4' && $contentscount > 0)) { unless (($cms eq 'bb5') && $key eq 'Top') { $seqtext{$key} = "\n"; @@ -773,7 +784,7 @@ sub build_structure { if (grep/^$res$/,@{$packages}) { $packageflag = 1; } - $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem}); + $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem},$title); unless ($flag{$key}{page} == 1) { if ($$randompicks{$contitem}) { $seqtext{$key} .= qq| @@ -813,7 +824,7 @@ sub build_structure { if (grep/^$res$/,@{$packages}) { $packageflag = 1; } - $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem}); + $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem},$title); unless ($flag{$key}{page} == 1) { $seqtext{$key} .= qq|> \n|; @@ -845,7 +856,7 @@ sub build_structure { if (grep/^$res$/,@{$packages}) { $packageflag = 1; } - $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem}); + $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem},$title); if ($flag{$key}{page}) { if ($count{$key}{seq} + $count{$key}{page} + $count{$key}{board} + $count{$key}{file} +1 == 1) { @@ -879,10 +890,15 @@ sub build_structure { } unless (($cms eq 'bb5') && $key eq 'Top') { $seqtext{$key} .= "\n"; - open(LOCFILE,">$destdir/sequences/$key.sequence"); + if ($cms eq 'webctce4' && $key ne 'Top') { + push @{$seqfiles}, "$seqtitle.sequence"; + open(LOCFILE,">$destdir/sequences/$seqtitle.sequence"); + } else { + push @{$seqfiles}, "$key.sequence"; + open(LOCFILE,">$destdir/sequences/$key.sequence"); + } print LOCFILE $seqtext{$key}; close(LOCFILE); - push @{$seqfiles}, "$key.sequence"; } $count{$key}{page} ++; $$total{page} += $count{$key}{page}; @@ -972,10 +988,16 @@ sub build_structure { } sub make_structure { - my ($cms,$key,$srcstem,$flag,$count,$timestamp,$boardnum,$hrefs,$pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$randompick) = @_; + my ($cms,$key,$srcstem,$flag,$count,$timestamp,$boardnum,$hrefs,$pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$randompick,$title) = @_; my $src =''; if (($cms eq 'angel' && $type eq 'FOLDER') || (($cms eq 'bb5' || $cms eq 'bb6') && (($$resinfo{$res}{'isfolder'} eq 'true') || $key eq 'Top')) || ($cms eq 'webctce4' && $contitemcount > 0)) { $src = $srcstem.'/sequences/'.$contitem.'.sequence'; + if ($cms eq 'webctce4') { + $title =~ s|/+|_|g; + $title =~ s/\s+/_/g; + $title .= '_'.$contitem; + $src = $srcstem.'/sequences/'.$title.'.sequence'; + } $$flag{$key}{page} = 0; $$flag{$key}{seq} = 1; $$count{$key}{seq} ++; @@ -1038,14 +1060,16 @@ sub make_structure { if ($file =~ m-/([^/]+)$-) { $filename = $1; } - $src = $srcstem.'/resfiles/'.$res.'/'.$filename; + $src = $srcstem.'/resfiles/'.$filename; } else { foreach my $file (@{$$hrefs{$res}}) { my $filename; - if ($file =~ m-/([^/]+)$-) { + if ($file =~ m-/my_files/(.+)$-) { + $filename = $1; + } elsif ($file =~ m-/([^/]+)$-) { $filename = $1; } - $src = $srcstem.'/resfiles/'.$res.'/'.$filename; + $src = $srcstem.'/resfiles/'.$filename; } } $$flag{$key}{page} = 0; @@ -2834,6 +2858,12 @@ sub parse_webct4_questionDB { $$settings{$id}{texttype} = $attr->{texttype}; $currtexttype = $attr->{texttype}; } + if ("@state" eq "questestinterop section item presentation flow material matimage") { + $$settings{$id}{imagtype} = $attr->{imagtype}; + $currimagtype = $attr->{imagtype}; + $$settings{$id}{uri} = $attr->{uri}; + + } if ("@state" eq "questestinterop section item presentation flow response_lid") { $$settings{$id}{class} = 'multiplechoice'; $list = $attr->{ident}; @@ -3053,12 +3083,18 @@ sub parse_webct4_questionDB { } } if ("@state" eq "questestinterop section item resprocessing respcondition setvar") { - if ($setvar{varname} eq "answerValue") { # Multiple Choice + if ($setvar{varname} eq "answerValue") { # Multiple Choice WebCT4.0 if ($text =~ m/^\d+$/) { if ($text > 0) { push(@{$$settings{$id}{$list}{correctanswer}},$answer_id); } } + } elsif ($setvar{varname} eq "que_score") { # Multiple Choice WebCT4.1 + if ($text =~ m/^\d+$/) { + if ($text > 0) { + push(@{$$settings{$id}{$list}{correctanswer}},$answer_id); + } + } } } if ("@state" eq "questestinterop section item resprocessing itemproc_extension webct:x_webct_v01_autocalculate webct:x_webct_v01_anstolerance") { @@ -3197,7 +3233,7 @@ sub build_category_sequences { push @{$sequencesfiles},'question_database.sequence'; foreach my $category (sort keys %{$catinfo}) { my $seqname; - if ($cms eq 'webct4ce') { + if ($cms eq 'webctce4') { $seqname = $$catinfo{$category}{title}.'_'.$category; } else { $seqname = $$catinfo{$category}{title}; @@ -3286,12 +3322,12 @@ sub build_problem_container { $probtitle{$id} =~ s/:/_/g; $probtitle{$id} .= '_'.$id; } - if (($cms eq 'webct4ce' && $container ne 'database') || + if (($cms eq 'webctce4' && $container ne 'database') || ($cms eq 'webctvista4')) { my $probdir; my $catid = $$settings{$$allids[0]}{category}; if ($catid) { - if ($cms eq 'webct4ce') { + if ($cms eq 'webctce4') { $probdir = $$catinfo{$catid}{title}.'_'.$catid; } else { $probdir = $$catinfo{$catid}{title}; @@ -3325,7 +3361,7 @@ sub build_problem_container { my $probdir; my $catid = $$settings{$$allids[$j]}{category}; if ($catid) { - if ($cms eq 'webct4ce') { + if ($cms eq 'webctce4') { $probdir = $$catinfo{$catid}{title}.'_'.$catid; } else { $probdir = $$catinfo{$catid}{title}; @@ -3756,7 +3792,7 @@ sub write_webct4_questions { if ($$settings{$id}{class} eq 'numerical') { foreach my $numid (@{$$settings{$id}{numids}}) { foreach my $var (keys %{$$settings{$id}{$numid}{vars}}) { - if ($cms eq 'webct4ce') { + if ($cms eq 'webctce4') { $$settings{$id}{text} =~ s/{($var)}/\$$1 /g; } elsif ($cms eq 'webctvista4') { $$settings{$id}{text} =~ s/\[($var)\]/\$$1 /g; @@ -3782,8 +3818,9 @@ sub write_webct4_questions { } } $$total{prob} ++; + if (exists($$settings{$id}{uri})) { - if ($cms eq 'webct4ce') { + if ($cms eq 'webctce4') { if ($$settings{$id}{imagtype} =~ /^image\//) { $questionimage = '

'."\n"; } else { @@ -4092,7 +4129,7 @@ $$settings{$id}{$list}{jumbledtext}[$k] ($$settings{$id}{class} eq 'shortanswer')) { my $labelnum = 0; my @str_labels = (); - if ($cms eq 'webct4ce') { + if ($cms eq 'webctce4') { foreach my $str_id (@{$$settings{$id}{str}}) { foreach my $label (@{$$settings{$id}{$str_id}{labels}}) { push(@str_labels,$label); @@ -4252,7 +4289,7 @@ $$settings{$id}{$list}{jumbledtext}[$k] } $increment .= '1'; } - if ($cms eq 'webct4ce') { + if ($cms eq 'webctce4') { $formula =~ s/{($var)}/(\$$1)/g; } elsif ($cms eq 'webctvista4') { $formula =~ s/\[($var)\]/(\$$1)/g; @@ -4305,7 +4342,7 @@ $$settings{$id}{$list}{jumbledtext}[$k] my $probdir; my $catid = $$settings{$id}{category}; if ($catid) { - if ($cms eq 'webct4ce') { + if ($cms eq 'webctce4') { $probdir = $$catinfo{$catid}{title}.'_'.$catid; } else { $probdir = $$catinfo{$catid}{title}; @@ -5291,20 +5328,18 @@ sub angel_content { # ---------------------------------------------------------------- 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|$destdir/resfiles/$res.html")) { + &Apache::lonnet::logthis("IMS import error: Cannot open file - $destdir/resfiles/$res.html - $!"); + } else { + push(@{$resrcfiles}, "$res.html"); + my $linktag = qq|$title|; } else { $linktag .= qq|>$$settings{url}|; } - } - print FILE qq| + print FILE qq| $title @@ -5312,7 +5347,8 @@ sub webct4_content { $linktag |; - close(FILE); + close(FILE); + } } }