--- loncom/imspackages/imsexport.pm 2012/01/29 19:51:01 1.8 +++ loncom/imspackages/imsexport.pm 2012/03/31 12:02:29 1.9 @@ -1,6 +1,6 @@ # The LearningOnline Network # -# $Id: imsexport.pm,v 1.8 2012/01/29 19:51:01 raeburn Exp $ +# $Id: imsexport.pm,v 1.9 2012/03/31 12:02:29 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -32,6 +32,7 @@ use Apache::lonnet; use Apache::loncommon; use Apache::lonhtmlcommon; use Apache::lonnavmaps; +use Apache::loncourserespicker; use Apache::lonlocal; use Cwd; use LONCAPA qw(:DEFAULT :match); @@ -39,40 +40,18 @@ use LONCAPA qw(:DEFAULT :match); sub exportcourse { my $r=shift; my $crstype = &Apache::loncommon::course_type(); - my %discussiontime = &Apache::lonnet::dump('discussiontimes', - $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); - my $numdisc = keys(%discussiontime); - my $numprobs = 0; - my $navmap = Apache::lonnavmaps::navmap->new(); - if (!defined($navmap)) { - $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package'). - '

'.&mt('IMS Export Failed').'

'. - '
'); - if ($crstype eq 'Community') { - $r->print(&mt('Unable to retrieve information about community contents')); - } else { - $r->print(&mt('Unable to retrieve information about course contents')); - } - $r->print('
'); - if ($crstype eq 'Community') { - $r->print(&mt('Return to Community Editor')); - } else { - $r->print(&mt('Return to Course Editor')); - } - $r->print(''); - &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'}); + my ($navmap,$errormsg) = + &Apache::loncourserespicker::get_navmap_object($crstype,'imsexport'); + unless (ref($navmap)) { + $r->print($errormsg); return; } - my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef); - my $curRes; - my $outcome; - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['finishexport']); if ($env{'form.finishexport'}) { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['archive','discussion']); - + my $outcome; my $format = $env{'form.format'}; my @exportitems = &Apache::loncommon::get_env_multiple('form.archive'); my @discussions = &Apache::loncommon::get_env_multiple('form.discussion'); @@ -138,181 +117,10 @@ sub exportcourse { $r->print($outcome); $r->print(&Apache::loncommon::end_page()); } else { - my $display='
'."\n". - '

'. - &mt('Choose which items you wish to export from your '.$crstype.'.'). - '

'. - '
'. - ''.&mt('Content items').''. - ''. - '  
'; - if ($numdisc > 0) { - $display .= '
'. - ''.&mt('Discussion posts').''. - ''. - '  '. - '
'; - } - $display .= '
'; - my $curRes; - my $depth = 0; - my $count = 0; - my $boards = 0; - my $startcount = 5; - my %parent = (); - my %children = (); - my $lastcontainer = $startcount; - $display .= &Apache::loncommon::start_data_table() - .&Apache::loncommon::start_data_table_header_row() - .''.&mt('Export content item?').''; - if ($numdisc > 0) { - $display .= ''.&mt('Export discussion posts?').''; - } - $display .= &Apache::loncommon::end_data_table_header_row(); - while ($curRes = $it->next()) { - if (ref($curRes)) { - $count ++; - } - if ($curRes == $it->BEGIN_MAP()) { - $depth++; - $parent{$depth} = $lastcontainer; - } - if ($curRes == $it->END_MAP()) { - $depth--; - $lastcontainer = $parent{$depth}; - } - if (ref($curRes)) { - my $symb = $curRes->symb(); - my $ressymb = $symb; - if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) { - unless ($ressymb =~ m|adm/wrapper/adm|) { - $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard'; - } - } - my $currelem = $count+$boards+$startcount; - $display .= &Apache::loncommon::start_data_table_row() - .''."\n" - .'is_sequence()) || ($curRes->is_page())) { - $lastcontainer = $currelem; - $display .= 'onclick="javascript:propagateCheck(this.form,'."'$currelem'".')"'; - } elsif ($curRes->is_problem()) { - $numprobs ++; - } - $display .= ' />'."\n"; - for (my $i=0; $i<$depth; $i++) { - $display .= ('' x2)."\n"; - } - if ($curRes->is_sequence()) { - $display .= ' '."\n"; - } elsif ($curRes->is_page()) { - $display .= ' '."\n"; - } - $children{$parent{$depth}} .= $currelem.':'; - $display .= ' '.$curRes->title().''."\n"; - - # Existing discussion posts? - if ($discussiontime{$ressymb} > 0) { - $boards ++; - $display .= '' - .'' - .''."\n"; - } elsif ($numdisc > 0) { - $display .= ' '."\n"; - } - $display .= &Apache::loncommon::end_data_table_row(); - } - } - $display .= &Apache::loncommon::end_data_table(); - my $numcount = $count + $boards + $startcount; - my $scripttag = &export_javascript($startcount,$numcount,%children); - $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package', - $scripttag)); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export')); - if ($numprobs > 0) { - $display .= '

'. - &mt('Export format for LON-CAPA problems:'). - ''.(' ' x3). - ''.(' ' x3). - '

'; - } - $r->print($display. - '

'. - '

'); + $r->print(&Apache::loncourserespicker::create_picker($navmap,'imsexport', + 'exportdoc',$crstype)); } -} - -sub export_javascript { - my ($startcount,$numitems,%children) = @_; - my $scripttag = <<"START"; - - -END - return $scripttag; + return; } sub create_ims_store { @@ -1075,8 +883,6 @@ described at http://www.lon-capa.org. =item exportcourse() -=item export_javascript() - =item create_ims_store() =item build_package()