--- loncom/imspackages/imsimport.pm 2004/02/23 14:14:45 1.2 +++ loncom/imspackages/imsimport.pm 2004/02/24 15:21:16 1.3 @@ -502,8 +502,8 @@ sub expand_bb5 { &process_group($key,$docroot,$destdir,\%{$resinfo{$key}}); } elsif ($type{$key} eq "resource/x-bb-user") { %{$resinfo{$key}} = (); - unless ($user_handling eq 'ignore') { - &process_user($key,$docroot,$destdir,\%{$resinfo{$key}},$user_crs,$user_cdom,$user_handling); + unless ($users_handling eq 'ignore') { + &process_user($key,$docroot,$destdir,\%{$resinfo{$key}},$users_crs,$users_cdom,$users_handling); } } } @@ -628,14 +628,6 @@ sub expand_bb5 { my $next_id = 1; my $curr_id = 0; if ( (($type{$resnum{$key}} eq "resource/x-bb-document") || ($type{$resnum{$key}} eq "resource/x-bb-staffinfo") || ($type{$resnum{$key}} eq "resource/x-bb-externallink")) && ($resinfo{$resnum{$key}}{'isfolder'} eq "true") ) { -# if ( ($type{$resnum{$key}} eq "resource/x-bb-staffinfo") && ($resinfo{$resnum{$key}}{'isfolder'} eq "true") ) { -# print "$key $filepath{$key} $resnum{$key} $title{$key}\n"; -# print "Folder for item - $key - res - $resnum{$key}\n"; -# print "$key, $contentscount{$key}\n"; -# foreach (@{$contents{$key}}) { -# print "$key, $_\n"; -# } -# print STDERR "Contents Count for $key is $contentscount{$key}\n"; open(LOCFILE,">$destdir/sequences/$key.sequence"); print LOCFILE "\n"; $totseq ++; @@ -880,14 +872,13 @@ sub process_user { $p->eof; my $configvars = &LONCAPA::Configuration::read_conf('loncapa.conf'); - my $xmlstem = $$configvars{'lonDaemons'}."/tmp/".$dom."_".$crs."_"; + my $xmlstem = $$configvars{'lonDaemons'}."/tmp/".$user_cdom."_".$user_crs."_"; - open (STUFILE,"> foreach my $user_id (keys %{$settings}) { if ($$settings{$user_id}{user_role} eq "s") { -# enroll as a single student + } elsif ($user_handling eq 'enrollall') { -# enroll as another user type + } } } @@ -1315,14 +1306,6 @@ sub process_db { $p->parse_file($xmlfile); $p->eof; -# if ($destcourse =~ m/^(\d)(\d)(\d)/) { -# $longcourse = $1.'/'.$2.'/'.$3.'/'.$destcourse; -# } -# my $bbfilename = '/home/httpd/lonUsers/'.$udom.'/'.$longcourse.'bulletinpage_'.$timestamp.'.db'; -# my %hash; -# tie(%hash,'GDBM_File',$bbfilename,&GDBM_WRCREAT,0640); -# $hash{'aaa_title'}=$$settings{title}; -# untie %hash; if (defined($$settings{text})) { if ($$settings{ishtml} eq "false") { if ($$settings{isnewline} eq "true") { @@ -2112,12 +2095,13 @@ $linktag|; } sub expand_angel { - my ($r,$uname,$udom,$fn,$page) = @_; + my ($r,$uname,$udom,$fn,$page,$bb_crs,$bb_cdom,$bb_handling) = @_; my @state = (); my @seq = "Top"; my $lastitem; my $itm = ''; my %resnum = (); + my %revitm = (); my %title = (); my %filepath = (); my %contentscount = ("Top" => 0); @@ -2170,7 +2154,10 @@ sub expand_angel { } if (("@state" eq $searchstr) && (@state > 3)) { $itm = $attr->{identifier}; - $resnum{$itm} = $attr->{identifierref}; + if ($attr->{identifierref} =~ m/^res(.+)$/) { + $resnum{$itm} = $1; + } + $revitm{$resnum{$itm}} = $itm; if ($start > @seq) { unless ($lastitem eq '') { push @seq, $lastitem; @@ -2205,13 +2192,17 @@ sub expand_angel { } } elsif ("@state" eq "manifest resources resource" ) { $identifier = $attr->{identifier}; - $file{$identifier} = $attr->{href}; + $identifier = substr($identifier,3); + if ($attr->{href} =~ m-^_assoc/$identifier/(.+)$-) { + $file{$identifier} = $1; + } @{$href{$identifier}} = (); } elsif ("@state" eq "manifest resources resource file") { - push @{$href{$identifier}},$attr->{href}; - if ($attr->{href} =~ m/^Icons\\icon(\w+)\.gif/) { + if ($attr->{href} =~ m/^_assoc\\$identifier\\(.+)$/) { + push @{$href{$identifier}},$1; + } elsif ($attr->{href} =~ m/^Icons\\icon(\w+)\.gif/) { $type{$identifier} = $1; - } + } } }, "tagname, attr"], text_h => @@ -2249,176 +2240,271 @@ sub expand_angel { } foreach my $key (sort keys %href) { foreach my $file (@{$href{$key}}) { - if ($file =~ m/^_assoc/) { - my $filepath = $file; - if (!-e "$destdir/resfiles/$key") { - mkdir("$destdir/resfiles/$key",0755); - } - while ($filepath =~ m-(\w+)\\(.+)-) { - $filepath = $2; - if (!-e "$destdir/resfiles/$key/$1") { - mkdir("$destdir/resfiles/$key/$1",0755); - } + print STDERR "File is $file, for $key\n"; + $file =~ s-\\-/-g; + my $filepath = $file; + if (!-e "$destdir/resfiles/$key") { + mkdir("$destdir/resfiles/$key",0755); + } + while ($filepath =~ m-(\w+)/(.+)-) { + $filepath = $2; + if (!-e "$destdir/resfiles/$key/$1") { + mkdir("$destdir/resfiles/$key/$1",0755); } - system("cp $docroot/temp/$key/$file $destdir/resfiles/$key/$file"); } + system("cp $docroot/temp/_assoc/$key/$file $destdir/resfiles/$key/$file"); } } -# ANGEL types FILE FOLDER PAGE MESSAGE FORM QUIZ BOARD +# ANGEL types FILE FOLDER PAGE LINK MESSAGE FORM QUIZ BOARD + my $currboard = ''; + my @boards = (); + my %messages = (); + my @timestamp = (); + my %boardnum = (); + my $board_id = time; + my $board_count = 0; foreach my $key (sort keys %type) { if ($type{$key} eq "BOARD") { + push @boards, $key; + $boardnum{$revitm{$key}} = $board_count ; + $currboard = $key; + @{$messages{$key}} = (); + $timestamp[$board_count] = $board_id; + $board_id ++; + $board_count ++; + } elsif ($type{$key} eq "MESSAGE") { + push @{$messages{$currboard}}, $key; + } elsif ($type{$key} eq "FILE" || $type{$key} eq "FOLDER" || $type{$key} eq "PAGE" || $type{$key} eq "LINK") { %{$resinfo{$key}} = (); - &angel_db($key,$docroot,$destdir,\%{$resinfo{$key}},$udom,$uname); - } elsif ($type{$key} eq "FILE" || $type{$key} eq "FOLDER" || $type{$key} eq "PAGE") { - %{$resinfo{$key}} = (); - &angel_content($key,$docroot,$dirname,$destdir,\%{$resinfo{$key}}); } elsif ($type{$key} eq "QUIZ") { %{$resinfo{$key}} = (); - &angel_assessment($key,$docroot,$dirname,$destdir,\%{$resinfo{$key}}); +# &angel_assessment($key,$docroot,$dirname,$destdir,\%{$resinfo{$key}}); } elsif ($type{$key} eq "FORM") { %{$resinfo{$key}} = (); - &angel_assessment($key,$docroot,$dirname,$destdir,\%{$resinfo{$key}}); +# &angel_assessment($key,$docroot,$dirname,$destdir,\%{$resinfo{$key}}); } } - my $nextnum = 0; - open(TOPFILE,">$destdir/sequences/ims_import.sequence"); - print TOPFILE "\n"; - my $fileopen = 0; - my $areakey; - my $areacount = 0; - my $lastentry = ''; - my $notlastentry = ''; + my $longcrs = ''; + if ($bb_crs =~ m/^(\d)(\d)(\d)/) { + $longcrs = $1.'/'.$2.'/'.$3.'/'.$bb_crs; + } + for (my $i=0; $i<@boards; $i++) { + my %msgidx = (); + my $forumtext = ''; + my $boardname = 'bulletinpage_'.$timestamp[$i]; + my $forumfile = "$destdir/resfiles/$boards[$i]/$file{$boards[$i]}"; + my @state = (); + my $p = HTML::Parser->new + ( + xml_mode => 1, + start_h => + [sub { + my ($tagname, $attr) = @_; + push @state, $tagname; + }, "tagname, attr"], + text_h => + [sub { + my ($text) = @_; + if ("@state" eq "html body div div") { + $forumtext = $text; + } + }, "dtext"], + end_h => + [sub { + my ($tagname) = @_; + pop @state; + }, "tagname"], + ); + $p->parse_file($xmlfile); + $p->eof; + + my %boardinfo = ( + 'aaa_title' => $title{$revitm{$boards[$i]}}, + 'bbb_content' => $forumtext, + 'ccc_webreferences' => '', + 'uploaded.lastmodified' => time, + ); + my $msgcount = 0; + + my $putresult = &Apache::lonnet::put($boardname,\%boardinfo,$bb_cdom,$bb_crs); + if ($bb_handling eq 'importall') { + foreach my $msg_id (@{$messages{$boards[$i]}}) { + $msgcount ++; + $msgidx{$msg_id} = $msgcount; + my %contrib = ( + 'sendername' => 'Username not recorded', + 'senderdomain' => $bb_cdom, + 'screenname' => '', + 'message' => $title{$revitm{$msg_id}} + ); + unless ( $parentseq{$revitm{$msg_id}} eq $revitm{$boards[$i]} ) { + $contrib{replyto} = $msgidx{$resnum{$parentseq{$revitm{$msg_id}}}}; + } + if ( @{$href{$msg_id}} > 1 ) { + my $newurl = ''; + foreach my $file (@{$href{$msg_id}}) { + unless ($file eq 'pg'.$msg_id.'.htm') { + $newurl = $msg_id.$file; + unless ($longcrs eq '') { + if (!-e "/home/httpd/lonUsers/$bb_cdom/$longcrs/userfiles") { + mkdir("/home/httpd/lonUsers/$bb_cdom/$longcrs/userfiles",0755); + } + if (!-e "/home/httpd/lonUsers/$bb_cdom/$longcrs/userfiles/$newurl") { + system("cp $destdir/resfiles/$file /home/httpd/lonUsers/$bb_cdom/$longcrs/userfiles/$newurl"); + } + $contrib{attachmenturl} = '/uploaded/'.$bb_cdom.'/'.$bb_crs.'/'.$newurl; + } + } + } + } + my $xmlfile = "$destdir/resfiles/$msg_id/$file{$msg_id}"; + &angel_message($msg_id,\%contrib,$xmlfile); + unless ($file{$msg_id} eq '') { + unlink($xmlfile); + } + my $symb = 'bulletin___'.$timestamp[$i].'___adm/wrapper/adm/'.$bb_cdom.'/'.$uname.'/'.$timestamp[$i].'/bulletinboard'; + my $postresult = &addposting($symb,\%contrib,$bb_cdom,$bb_crs); + } + } + } + + my @resources = sort keys %resnum; + unshift @resources, "Top"; + $resnum{'Top'} = 'toplevel'; + $type{'toplevel'} = "FOLDER"; + my %pagecount = (); my %pagecontents = (); my %pageflag = (); my %seqflag = (); my %seqcount = (); + my %boardflag = (); + my %boardcount = (); - foreach my $key (sort keys %resnum) { + foreach my $key (@resources) { + print STDERR "Key is $key, resnum is $resnum{$key}, type is $type{$resnum{$key}}\n"; $pageflag{$key} = 0; $seqflag{$key} = 0; $seqcount{$key} = 0; $pagecount{$key} = -1; - if ($filepath{$key} eq 'Top') { - $topnum ++; - $nextnum = $topnum +1; - print TOPFILE qq| -\n|; - if ($topnum == $contentscount{'Top'}) { - print TOPFILE qq|\n|; - } - } else { - if ($topnum == $contentscount{'Top'}) { - print TOPFILE qq| type="finish">\n|; - } else { - print TOPFILE qq|> -\n|; - } - } - - my $src =""; - my $next_id = 1; - my $curr_id = 0; - if ($type{$resnum{$key}} eq "FOLDER") { - open(LOCFILE,">$destdir/sequences/$key.sequence"); - print LOCFILE "\n"; - if ($contentscount{$key} == 0) { - print LOCFILE qq| + $boardflag{$key} = 0; + $boardcount{$key} = 0; + my $src =""; + my $next_id = 1; + my $curr_id = 0; + if ($type{$resnum{$key}} eq "FOLDER") { + open(LOCFILE,">$destdir/sequences/$key.sequence"); + print LOCFILE "\n"; + if ($contentscount{$key} == 0) { + print LOCFILE qq| \n|; - } else { - if ($type{$resnum{$contents{$key}[0]}} eq "FOLDER") { - $src = 'sequences/'.$contents{$key}[0].".sequence"; - $pageflag{$key} = 0; - $seqflag{$key} = 1; - $seqcount{$key} ++; + } else { + if ($type{$resnum{$contents{$key}[0]}} eq "FOLDER") { + $src = 'sequences/'.$contents{$key}[0].".sequence"; + $pageflag{$key} = 0; + $seqflag{$key} = 1; + $seqcount{$key} ++; + } elsif ($type{$resnum{$contents{$key}[0]}} eq "BOARD") { + $src = "/adm/$bb_cdom/$uname/$timestamp[$boardnum{$key}]/bulletinboard"; + $pageflag{$key} = 0; + $boardflag{$key} = 1; + $boardcount{$key} ++; + } elsif ($type{$resnum{$contents{$key}[0]}} ne "MESSAGE") { + if ($pageflag{$key}) { + push @{$pagecontents{$key}[$pagecount{$key}]},$contents{$key}[0]; } else { - if ($pageflag{$key}) { - push @{$pagecontents{$key}[$pagecount{$key}]},$contents{$key}[0]; } else { - $pagecount{$key} ++; - $src = 'pages/'.$key.'_'.$pagecount{$key}.'.page'; - @{$pagecontents{$key}[$pagecount{$key}]} = ("$contents{$key}[0]"); - $seqflag{$key} = 0; - } + $pagecount{$key} ++; + $src = 'pages/'.$key.'_'.$pagecount{$key}.'.page'; + @{$pagecontents{$key}[$pagecount{$key}]} = ("$contents{$key}[0]"); + $seqflag{$key} = 0; } - unless ($pageflag{$key}) { - print LOCFILE qq| + } + if ($contentscount{$key} == 1) { + print LOCFILE qq|> \n|; - } else { - if ($contentscount{$key} > 2 ) { - for (my $i=1; $i<$contentscount{$key}-1; $i++) { - if ($resinfo{$resnum{$contents{$key}[$i]}}{'isfolder'} eq "true") { - $src = 'sequences/'.$contents{$key}[$i].".sequence"; - $pageflag{$key} = 0; - $seqflag{$key} = 1; - $seqcount{$key} ++; + } else { + if ($contentscount{$key} > 2 ) { + for (my $i=1; $i<$contentscount{$key}-1; $i++) { + if ($type{$resnum{$contents{$key}[$i]}} eq "FOLDER") { + $src = 'sequences/'.$contents{$key}[$i].".sequence"; + $pageflag{$key} = 0; + $seqflag{$key} = 1; + $seqcount{$key} ++; + } elsif ($type{$resnum{$contents{$key}[0]}} eq "BOARD") { + $src = "/adm/$bb_cdom/$uname/$timestamp[$boardnum{$key}]/bulletinboard"; + $pageflag{$key} = 0; + $boardflag{$key} = 1; + $boardcount{$key} ++; + } elsif ($type{$resnum{$contents{$key}[0]}} ne "MESSAGE") { + if ($pageflag{$key}) { + push @{$pagecontents{$key}[$pagecount{$key}]},$contents{$key}[$i]; } else { - if ($pageflag{$key}) { - push @{$pagecontents{$key}[$pagecount{$key}]},$contents{$key}[$i]; - } else { - $pagecount{$key} ++; - $src = 'pages/'.$key.'_'.$pagecount{$key}.'.page'; - @{$pagecontents{$key}[$pagecount{$key}]} = ("$contents{$key}[$i]"); - $seqflag{$key} = 0; - } + $pagecount{$key} ++; + $src = 'pages/'.$key.'_'.$pagecount{$key}.'.page'; + @{$pagecontents{$key}[$pagecount{$key}]} = ("$contents{$key}[$i]"); + $seqflag{$key} = 0; } - unless ($pageflag{$key}) { - $curr_id ++; - $next_id ++; - print LOCFILE qq|> + } + unless ($pageflag{$key}) { + $curr_id ++; + $next_id ++; + print LOCFILE qq|> + } + if ($pageflag{$key}) { + if ($seqcount{$key} + $pagecount{$key} + $boardcount{$key} +1 == 1) { + print LOCFILE qq|> \n|; - } else { - print LOCFILE qq| type="finish">\n|; - } } else { - $curr_id ++; - $next_id ++; - print LOCFILE qq|> + print LOCFILE qq| type="finish">\n|; + } + } else { + $curr_id ++; + $next_id ++; + print LOCFILE qq|> \n|; - } } } - print LOCFILE "\n"; - close(LOCFILE); } + print LOCFILE "\n"; + close(LOCFILE); + } } foreach my $key (sort keys %pagecontents) { @@ -2448,7 +2534,37 @@ sub expand_angel { close(PAGEFILE); } } - system(" rm -r $docroot/temp"); +# system(" rm -r $docroot/temp"); +} + +sub angel_message { + my ($msg_id,$contrib,$xmlfile) = @_; + my @state = (); + my $p = HTML::Parser->new + ( + xml_mode => 1, + start_h => + [sub { + my ($tagname, $attr) = @_; + push @state, $tagname; + }, "tagname, attr"], + text_h => + [sub { + my ($text) = @_; + if ("@state" eq "html body table tr td div small span") { + $$contrib{'plainname'} = $text; + } elsif ("@state" eq "html body div div") { + $$contrib{'message'} .= '

'.$text; + } + }, "dtext"], + end_h => + [sub { + my ($tagname) = @_; + pop @state; + }, "tagname"], + ); + $p->parse_file($xmlfile); + $p->eof; } sub get_ccroles { @@ -2576,13 +2692,13 @@ sub handler { if ($ENV{'form.phase'} eq 'three') { $current_page = &display_control(); - my @PAGES = ('ChooseDir','Blackboard5','ANGEL','WebCT'); + my @PAGES = ('ChooseDir','Confirmation'); $page_name = $PAGES[$current_page]; if ($page_name eq 'ChooseDir') { &jscript_zero($fullpath,\$javascript,$uname,$udom); } elsif ($page_name eq 'Confirmation') { - &jscript_two(\$javascript,$uname); +# &jscript_two(\$javascript,$uname); } } elsif ($ENV{'form.phase'} eq 'two') { &jscript_zero($fullpath,\$javascript,$uname,$udom); @@ -2600,6 +2716,7 @@ sub handler { my $bb_crs = ''; my $bb_cdom = ''; my $bb_handling = ''; + my $source = $ENV{'form.source'}; if ( defined($ENV{'form.bb_crs'}) ) { ($bb_cdom,$bb_crs) = split/\//,$ENV{'form.bb_crs'}; } @@ -2616,10 +2733,14 @@ sub handler { $users_handling = $ENV{'form.user_handling'}; } my ($totseq,$totpage,$totprob); - &display_zero ($r,$uname,$fn,$current_page,$fullpath) if $page_name eq 'ChooseDir'; - ($totseq,$totpage,$totprob) = &expand_bb5 ($r,$uname,$udom,$fn,$current_page,$bb_crs,$bb_cdom,$bb_handling,$users_crs,$users_cdom,$users_handling) if $page_name eq 'Blackboard5'; - ($totseq,$totpage,$totprob) = &expand_angel ($r,$uname,$udom,$fn,$current_page) if $page_name eq 'ANGEL'; - &expand_webct ($r,$uname,$udom,$fn,$current_page) if $page_name eq 'WebCT'; + print STDERR "Page name is $page_name\n"; + if ($page_name eq 'ChooseDir') { + &display_zero ($r,$uname,$fn,$current_page,$fullpath); + } elsif ($page_name eq 'Confirmation') { + ($totseq,$totpage,$totprob) = &expand_bb5 ($r,$uname,$udom,$fn,$current_page,$bb_crs,$bb_cdom,$bb_handling,$users_crs,$users_cdom,$users_handling) if $source eq 'bb5'; + ($totseq,$totpage,$totprob) = &expand_angel ($r,$uname,$udom,$fn,$current_page,$bb_crs,$bb_cdom,$bb_handling) if $source eq 'angel'; + &expand_webct ($r,$uname,$udom,$fn,$current_page) if $source eq 'webct'; + } $r->print("

Step 3: Publish your new LON-CAPA materials

"); $r->print("Your IMS package has been processed successfully. A total of $totseq sequences, $totpage pages, and $totprob problems have been created.

\n");