--- loncom/imspackages/imsimportdocs.pm 2005/10/27 18:19:36 1.14 +++ loncom/imspackages/imsimportdocs.pm 2009/11/20 11:16:59 1.25 @@ -1,3 +1,7 @@ +# The LearningOnline Network with CAPA +# +# $Id: imsimportdocs.pm,v 1.25 2009/11/20 11:16:59 bisitz Exp $ +# # Copyright Michigan State University Board of Trustees # # This file is part of the LearningOnline Network with CAPA (LON-CAPA). @@ -30,6 +34,10 @@ use Apache::loncommon; use Apache::lonlocal; use Apache::imsprocessor; use LONCAPA::Configuration; +use LONCAPA::map(); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + use strict; sub jscript_one { @@ -150,15 +158,22 @@ sub handler { my $uname=$env{'user.name'}; my $udom=$env{'user.domain'}; - my $plainname=&Apache::lonnet::escape( + my $plainname=&escape( &Apache::loncommon::plainname($uname,$udom)); # does this user have privileges to post, etc? my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'}); unless ($allowed) { - $r->print("The LearningOnline Network with CAPA"); - $r->print(&Apache::loncommon::bodytag('Import IMS package',undef,'',1)); - $r->print('

'.&mt('Modification of Course Contents Disallowed').'

'.&mt('Your current role does not grant you the right to modify course content in this course.').''); + $r->print(&Apache::loncommon::start_page('Import IMS package',undef, + {'only_body' => 1,})); + $r->print( + '

' + .&mt('Modification of Course Contents Disallowed') + .'

' + .&mt('Your current role does not grant you the right to modify course content in this course.') + .'

' + .&Apache::loncommon::end_page() + ); return OK; } @@ -173,20 +188,17 @@ sub handler { &jscript_three(\$javascript); } + $javascript = + "\n"; + my $headline = 'Import IMS package'; + my $start_page = &Apache::loncommon::start_page($headline, + $javascript, + {'only_body' => 1,}) + .'

'.&mt($headline).'

'; # print screen - $r->print(< - -The LearningOnline Network with CAPA - - -ENDHEAD -# -------------------------------------------------------------------- Body tag - $r->print(&Apache::loncommon::bodytag('Import IMS package',undef,'',1)); + $r->print($start_page); + if ($env{'form.phase'} eq 'one') { &display_one($r); } elsif ($env{'form.phase'} eq 'two') { @@ -194,7 +206,7 @@ ENDHEAD } elsif ($env{'form.phase'} eq 'three') { &display_three($r,$coursenum,$coursedom,$uname,$udom,\@areas,%cmsmap); } - $r->print(""); + $r->print(&Apache::loncommon::end_page()); return OK; } @@ -203,96 +215,38 @@ sub display_one { my ($r) = @_; &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder']); - $r->print(< - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  -
  -    - Specify the Course Management system used to create the package.   - -
 
  - -Please choose the CMS used to create your IMS content package.   - - -
 
 
  -    - Locate the IMS content package you wish to upload.   - -
 
  - - - -
 
 If you have selected the CMS, and located the IMS package, you should click the 'Upload IMS package' button to upload the file to the server.
 
- - - - -
- - - -
-
- - - - -ENDBLOCK + $r->print( + '
' + .&Apache::lonhtmlcommon::topic_bar( + 1,&mt('Specify the Course Management system used to create the package')) + .&mt('Please choose the CMS used to create your IMS content package:').' ' + .'' + ); + $r->print( + &Apache::lonhtmlcommon::topic_bar( + 2,&mt('Locate the IMS content package you wish to upload')) + .'' + .'' + .&mt('File:') + .' ' + ); + $r->print( + '
' + .'

' + .'' + .' ' + .'' + .'

' + ); } @@ -332,28 +286,57 @@ sub display_two { users => 0, ); - if ($unzip_result eq 'ok') { - $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,\%resources,\%items,\%hrefs,\%resinfo,'choose',\%includedres,\%includeditems); - if ($manifest_result eq 'ok') { - foreach my $res (sort keys %resources) { - if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webct4') { - foreach my $area (keys %{$cmsmap{$cms}}) { - if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) { - $count{$area} ++; - } - } - } elsif ($cms eq 'angel') { - foreach my $area (keys %{$cmsmap{$cms}}) { - if ($area eq 'doc') { - if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) { - $count{$area} ++; - } - } elsif ($resources{$res}{type} eq $cmsmap{$cms}{$area}) { - $count{$area} ++; - } + if ($unzip_result ne 'ok') { + $r->print( + '

' + .&mt('Processing of your IMS package failed because the file you' + .' uploaded could not be unzipped.') + .'

' + ); + return(); + } + + # Get manifest file from package + $manifest_result = &Apache::imsprocessor::process_manifest( + $cms,$tempdir,\%resources,\%items,\%hrefs, + \%resinfo,'choose',\%includedres,\%includeditems); + if ($manifest_result ne 'ok') { + $r->print( + '

' + .&mt('Unpacking of your IMS package failed because an IMS manifest file was not located in the package.') + .'

' + ); + return(); + } + + # Count areas depending on cms version + foreach my $res (sort keys %resources) { + if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4') { + foreach my $area (keys %{$cmsmap{$cms}}) { + if ($resources{$res}{type} eq $cmsmap{$cms}{$area}) { + $count{$area} ++; + } + } + } elsif ($cms eq 'angel5') { + foreach my $area (keys %{$cmsmap{$cms}}) { + if ($area eq 'doc') { + if (grep/^$resources{$res}{type}$/,@{$cmsmap{$cms}{doc}}) { + $count{$area} ++; } + } elsif ($resources{$res}{type} eq $cmsmap{$cms}{$area}) { + $count{$area} ++; } } + } else { # Unknown cms format + $r->print( + '' + .&mt('Unsupported IMS format: [_1]',$cms) + .'
' + ); + # return(); + } + } + $r->print(< @@ -365,7 +348,7 @@ sub display_two { - "); } elsif ($area eq 'users') { $r->print(" "); @@ -435,10 +418,10 @@ ENDBLOCK - @@ -449,10 +432,10 @@ ENDBLOCK @@ -477,10 +460,10 @@ ENDBLOCK
+ 3    Choose which content types you wish to import @@ -403,13 +386,13 @@ ENDBLOCK if ($area eq 'board') { $r->print("        

+ 4    - Choose display options for listing of contents of top level of package. + Choose display options for listing of contents of top level of package
- + - +
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.
- + - +
@@ -491,12 +474,6 @@ ENDBLOCK ENDDOCUMENT - } else { - $r->print("Unpacking of your IMS package failed because an IMS manifest file was not located in the package\n"); - } - } else { - $r->print("Processing of your IMS package failed because the file you uploaded could not be unzipped\n"); - } } @@ -549,7 +526,7 @@ sub display_three { foreach my $area (@{$areas}) { if (defined($env{"form.$area"}) && ($env{'form.'.$area} ne '')) { - if ($cms eq 'angel' && $area eq 'doc') { + if ($cms eq 'angel5' && $area eq 'doc') { foreach (@{$cmsmap{$cms}{$area}}) { $importareas{$_} = 1; } @@ -635,25 +612,25 @@ sub display_three { 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; + my $url = &unescape($topurls[$i]); + my $name = &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 $url = &unescape("/uploaded/$cdom/$crs/$timenow/sequences/Top.sequence"); + my $name = &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]=''; + if ($#LONCAPA::map::order<1) { + $LONCAPA::map::order[0]=1; + $LONCAPA::map::resources[1]=''; } my ($errtext,$fatal)=&Apache::londocs::group_import($crs,$cdom,$folder,'sequence','imsimport',@imports); if ($fatal) { - print STDERR "Fatal error during group_import\n"; + &Apache::lonnet::logthis("Fatal error during group_import."); } } if ($tempdir =~ m/^\/home\/httpd\/perl\/tmp\/$crs\/\d{10}/) { @@ -669,7 +646,7 @@ sub display_three { - + 5    Your import is complete @@ -690,7 +667,7 @@ ENDBLOCK |; + $initblock .= qq|" onClick="javascript:init(this.form)" />|; $initblock .= ', '.&mt('or the next time you log in.'); $initblock .= qq||; $r->print($initblock);