--- loncom/imspackages/imsimportdocs.pm 2004/03/02 15:45:06 1.1 +++ loncom/imspackages/imsimportdocs.pm 2004/03/09 16:34:34 1.2 @@ -1,10 +1,13 @@ package Apache::imsimportdocs; +use Apache::Constants qw(:common :http :methods); use Apache::lonnet; +use Apache::londocs; use Apache::loncommon; use Apache::lonlocal; use Apache::imsprocessor; use LONCAPA::Configuration; +use strict; sub jscript_one { my $javascript = shift; @@ -94,6 +97,16 @@ function nextPage(caller) { #; } +sub jscript_three { + my $javascript = shift; + $$javascript = qq| +function init(tf) { + setTimeout("self.close()",3000) + tf.submit(); +} + |; +} + sub handler { my $r = shift; my $javascript = ''; @@ -153,6 +166,8 @@ sub handler { &jscript_one(\$javascript); } elsif ($ENV{'form.phase'} eq 'two') { &jscript_two(\$javascript); + } elsif ($ENV{'form.phase'} eq 'three') { + &jscript_three(\$javascript); } # print screen @@ -174,9 +189,10 @@ ENDHEAD } elsif ($ENV{'form.phase'} eq 'two') { &display_two($r,$coursenum,\@areas,%cmsmap); } elsif ($ENV{'form.phase'} eq 'three') { - &display_three($r,$coursenum,$coursedom,$coursehome,\@areas,%cmsmap); + &display_three($r,$coursenum,$coursedom,$coursehome,$uname,$udom,\@areas,%cmsmap); } $r->print(""); + return OK; } sub uploadzip { @@ -202,8 +218,7 @@ sub uploadzip { } sub display_one { - my $r = shift; - my $timestamp = time; + my ($r) = @_; &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']); $r->print(<  $areaname{$area}   - $count{$area} item(s)"); if ($area eq 'board') { $r->print("    - "); @@ -443,9 +460,35 @@ ENDBLOCK  

+ + + +    + Choose display options for listing of contents of top level of package. + + + +   +   - Once you have checked the checkboxes for all areas you wish to import from the IMS package, and selected options (if available) you should click the 'Complete Import' button. + + + + + + + + +
Display listing of contents in a new folder, with folder name:   
Append listing of contents of top level of package to contents list for the current folder.
+ + + +   + + +   + Once you have checked the checkboxes for all areas you wish to import from the IMS package, selected options (if available), and selected a display option for the package contents you should click the 'Complete Import' button.   @@ -484,38 +527,173 @@ ENDDOCUMENT sub display_three { - my ($r,$crs,$cdom,$chome,$areas,%cmsmap) = @_; - $r->print("You reached phase three"); - my $cms = $ENV{'form.source'}; - my $tempdir = $ENV{'form.tempdir'}; - my $longcrs = ''; - if ($crs =~ m/^(\d)(\d)(\d)/) { - $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs; - } - my $destdir = ''; - my %imports = (); - my @targets = (); - my %resources = (); - my %items = (); - my %hrefs = (); - my %urls = (); - foreach my $area (@{$areas}) { - if (defined($ENV{"form.$area"}) ) { - if ($cms eq 'angel' && $area eq 'doc') { - foreach (@{$cmsmap{$cms}{$area}}) { - $imports{$_} = 1; - } - } else { - $imports{$cmsmap{$cms}{$area}} = 1; - } - } - } + my ($r,$crs,$cdom,$chome,$uname,$udom,$areas,%cmsmap) = @_; + my $folder = $ENV{'form.folder'}; + my $cms = $ENV{'form.source'}; + my $tempdir = $ENV{'form.tempdir'}; + my $longcrs = ''; + if ($crs =~ m/^(\d)(\d)(\d)/) { + $longcrs = $1.'/'.$2.'/'.$3.'/'.$crs; + } + my %imports = (); + my @targets = (); + my %resources = (); + my %items = (); + my %hrefs = (); + my %urls = (); + my %resinfo = (); + my %total = ( + page => 0, + prob => 0, + seq => 0, + board => 0, + quiz => 0, + surv => 0, + ); + my @pages = (); + my @sequences = (); + my @resrcfiles = (); + + my $timenow = time; + + my $destdir = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles/'.$cdom.'/'.$crs.'/'.$timenow; + my $dirname = $cdom.'/'.$crs.'/'.$timenow; + my $seqstem = "/uploaded/$cdom/$crs/$timenow"; + my $db_handling = ''; + my $user_handling = ''; + + my $toplevel = ''; + my $foldername = ''; + my %topitems = (); + if (defined($ENV{'form.toplevel'}) ) { + $toplevel = $ENV{'form.toplevel'}; + } + if (defined($ENV{'form.foldername'}) ) { + $foldername = $ENV{'form.foldername'}; + } + + foreach my $area (@{$areas}) { + if (defined($ENV{"form.$area"}) ) { + if ($cms eq 'angel' && $area eq 'doc') { + foreach (@{$cmsmap{$cms}{$area}}) { + $imports{$_} = 1; + } + } else { + $imports{$cmsmap{$cms}{$area}} = 1; + } + if ($area eq 'board') { + $db_handling = $ENV{'form.db_handling'}; + } elsif ($area eq 'users') { + $user_handling = $ENV{'form.user_handling'}; + } + } + } - my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs); - if ($manifest_result eq 'ok') { - &Apache::imsprocessor::target_resources(\%resources,\%imports,\@targets); - $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$chome,$destdir); - } + my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo); + if ($manifest_result eq 'ok') { + &Apache::imsprocessor::target_resources(\%resources,\%imports,\@targets); + my $copy_result = &Apache::imsprocessor::copy_resources('DOCS',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$chome,$destdir,$timenow); + + my @boards = (); + my @announcements = (); + my @quizzes = (); + my @surveys = (); + my @groups = (); + my %messages = (); + my @timestamp = (); + my %boardnum = (); + my @topurls = (); + my @topnames = (); + + &Apache::imsprocessor::process_resinfo($cms,$tempdir,$destdir,\%items,\%resources,\@boards,\@announcements,\@quizzes,\@surveys,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$dirname,$seqstem,\@resrcfiles); + + &Apache::imsprocessor::build_structure($cms,'DOCS',$destdir,\%resinfo,\%items,\%resources,\%hrefs,$udom,$uname,'',$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames); + + foreach my $item (@pages) { + my $path = $timenow.'/pages/'; + ©_items($item,$path,$cdom,$chome,$crs); + } + foreach my $item (@sequences) { + unless ($item eq 'Top.sequence' && $toplevel eq 'oldfolder') { + my $path = $timenow.'/sequences/'; + ©_items($item,$path,$cdom,$chome,$crs); + } + } + foreach my $item (@resrcfiles) { + my $path = $timenow.'/resfiles/'; + ©_items($item,$path,$cdom,$chome,$crs); + } + + my @imports = (); + if ($toplevel eq 'oldfolder') { + for (my $i=0; $i<@topurls; $i++) { + my $url = &Apache::lonnet::unescape($topurls[$i]); + my $name = &Apache::lonnet::unescape($topnames[$i]); + push @imports, $name, $url; + } + } elsif ($toplevel eq 'newfolder') { + my $url = &Apache::lonnet::unescape("/uploaded/$cdom/$crs/$timenow/sequences/Top.sequence"); + my $name = &Apache::lonnet::unescape("$ENV{'form.foldername'}"); + push @imports, $name, $url; + } + my $errtext=''; + my $fatal=0; + ($errtext,$fatal)= &Apache::londocs::mapread($crs,$cdom,$folder.'.sequence'); + if ($#Apache::lonratedt::order<1) { + $Apache::lonratedt::order[0]=1; + $Apache::lonratedt::resources[1]=''; + } + my ($errtext,$fatal)=&Apache::londocs::group_import($crs, $cdom, $folder,@imports); + if ($fatal) { + print STDERR "Fatal error during group_import\n"; + } + } + $r->print(< + + + + + + + + + + + + + + + + + +
  +
+    + Your import is complete +
 
  +ENDBLOCK + my $initblock = qq| +
+ + +

Changes will become active for your current session after + + |; + $initblock .= &mt('or the next time you log in.'); + $initblock .= qq|

|; + $r->print($initblock); + $r->print(< +
+ENDBLOCKTWO +} + +sub copy_items { + my ($filename,$fpath,$cdom,$chome,$crs) = @_; + my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$cdom.'/'.$crs.'/'.$filename.':'.$fpath,$chome); } 1;