--- loncom/imspackages/imsexport.pm 2012/01/29 19:51:01 1.8 +++ loncom/imspackages/imsexport.pm 2016/06/20 16:39:26 1.13 @@ -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.13 2016/06/20 16:39:26 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -32,6 +32,8 @@ use Apache::lonnet; use Apache::loncommon; use Apache::lonhtmlcommon; use Apache::lonnavmaps; +use Apache::loncourserespicker; +use Apache::londocs; use Apache::lonlocal; use Cwd; use LONCAPA qw(:DEFAULT :match); @@ -39,40 +41,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'); @@ -135,184 +115,15 @@ sub exportcourse { } $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package')); $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export')); + $r->print(&Apache::londocs::startContentScreen('tools')); $r->print($outcome); + $r->print(&Apache::londocs::endContentScreen()); $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. - '

'. - '

'); - } -} - -sub export_javascript { - my ($startcount,$numitems,%children) = @_; - my $scripttag = <<"START"; - - -END - return $scripttag; + return; } sub create_ims_store { @@ -584,17 +395,17 @@ sub process_content { } } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) { $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded'); - } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) { - my $canedit = 0; - if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'}) { - $canedit= 1; - } -# only include problem code where current user is author + } elsif ($symb =~ m-\.(?:sequence|page)___\d+___($match_domain/$match_name/.+)$-) { + my $url = &Apache::lonnet::clutter($1); + $url =~ s{^/res/}{/priv/}; if (($format eq 'html') || ($format eq 'plaintext')) { my $title = $curRes->title; $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,$format,$currdirpath,$title,$testbank); } elsif ($format eq 'xml') { - if ($canedit) { +# only include problem code where current user is author or co-author, +# or this is a course "author" resource. + my ($ownername,$ownerdom,$ownerhome) = &Apache::lonnet::constructaccess($url); + if (($ownername ne '') && ($ownerdom ne '') && ($ownerhome ne '')) { $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource'); } else { $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit'); @@ -862,6 +673,7 @@ sub simpleproblem { %values = &evaloptionhash($options); $output .= qq| + $qtext |; @@ -890,8 +702,9 @@ sub simpleproblem { } else { $output .= qq| + $qtext - + |; for (my $k=0; $k<10; $k++) { my $iter = $k+1; @@ -916,14 +729,14 @@ sub simpleproblem { |; } - } elsif ($qtype eq 'stringanswer') { + } elsif ($qtype eq 'string') { my $stringanswer = $qparms{$prefix.'stringanswer'}; my $stringtype=$qparms{$prefix.'stringtype'}; $output .= qq| - - + $qtext + |; if ($hint) { $output .= ' @@ -937,6 +750,55 @@ sub simpleproblem { |; + } elsif ($qtype eq 'numerical') { + my $sigfigs = $qparms{$prefix.'numericalsigfigs'}; + my $unit = $qparms{$prefix.'numericalunit'}; + my $answer = $qparms{$prefix.'numericalanswer'}; + my $tolerance = $qparms{$prefix.'numericaltolerance'}; + my $format = $qparms{$prefix.'numericalformat'}; + my $scriptblock = $qparms{$prefix.'numericalscript'}; + $output .= qq| + +|; + if ($scriptblock) { + $output .= qq| +|; + } + $output .= qq| +$qtext +|; + } + if ($sigfigs) { + $output .= qq| + |; + } + $output .= qq| + |; + if ($hint) { + $output .= qq| + + + '.$hint.' + + |; + } + $output .= qq| + + +|; } else { $output .= qq| @@ -1035,7 +897,7 @@ sub templatedpage { $udom |; } - foreach (sort keys %syllabusfields) { + foreach (sort(keys(%syllabusfields))) { $output .= qq| <$_> $syllabusfields{$_} @@ -1075,8 +937,6 @@ described at http://www.lon-capa.org. =item exportcourse() -=item export_javascript() - =item create_ims_store() =item build_package()