Index: loncom/interface/londocs.pm diff -u loncom/interface/londocs.pm:1.453 loncom/interface/londocs.pm:1.454 --- loncom/interface/londocs.pm:1.453 Fri May 27 19:02:16 2011 +++ loncom/interface/londocs.pm Mon Jul 4 13:01:53 2011 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.453 2011/05/27 19:02:16 raeburn Exp $ +# $Id: londocs.pm,v 1.454 2011/07/04 13:01:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -280,6 +280,7 @@ 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'). @@ -310,6 +311,7 @@ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['archive','discussion']); + my $format = $env{'form.format'}; my @exportitems = &Apache::loncommon::get_env_multiple('form.archive'); my @discussions = &Apache::loncommon::get_env_multiple('form.discussion'); if (@exportitems == 0 && @discussions == 0) { @@ -331,9 +333,10 @@ my $imsresources; my $tempexport; my $copyresult; - my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport); + my $testbank; + my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport,$format,\$testbank); if ($manifestok) { - &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest); + &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest,$format,$testbank); close($ims_manifest); #Create zip file in prtspool @@ -435,6 +438,8 @@ if (($curRes->is_sequence()) || ($curRes->is_page())) { $lastcontainer = $currelem; $display .= 'onclick="javascript:propagateCheck('."'$currelem'".')"'; + } elsif ($curRes->is_problem()) { + $numprobs ++; } $display .= ' />'."\n"; for (my $i=0; $i<$depth; $i++) { @@ -519,6 +524,16 @@ $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. '

'. ''."\n". ' '."\n". -' '.$env{'course.'.$env{'request.course.id'}.'.description'}.'' +' '.$env{'course.'.$env{'request.course.id'}.'.description'}.''; + if ($format eq 'plaintext') { + my $testbankfilename = $$tempexport.'/testbank.txt'; + $$testbank = Apache::File->new('>'.$testbankfilename); + } } else { $$outcome .= 'An error occurred opening the IMS manifest file.
' ; @@ -580,7 +599,8 @@ } sub build_package { - my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_; + my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult, + $ims_manifest,$format,$testbank) = @_; # first iterator to look for dependencies my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef); my $curRes; @@ -619,6 +639,7 @@ $count = 0; my $imsresources; my $pkgdepth; + my $currdirpath = 'Top'; while ($curRes = $it->next()) { if ($curRes == $it->BEGIN_MAP()) { $prevdepth = $depth; @@ -656,10 +677,27 @@ ''.$curRes->title().''; print $ims_manifest "\n".$itementry; - unless ($curRes->is_sequence()) { + if ($curRes->is_sequence()) { + $currdirpath = 'Top'; + my $pcslist = $curRes->map_hierarchy(); + if ($pcslist ne '') { + foreach my $pc (split(/,/,$pcslist)) { + my $res = $navmap->getByMapPc($pc); + if (ref($res)) { + my $encloser = $res->title(); + if ($encloser) { + if ($currdirpath) { + $currdirpath .= ' -> '; + } + $currdirpath .= $encloser; + } + } + } + } + } else { my $content_file; my @hrefs = (); - &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport); + &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport,$format,$currdirpath,$testbank); if ($content_file) { $imsresources .= "\n". ' \n"; } - } elsif ($caller eq 'noedit') { + } elsif (($caller eq 'noedit') || ($caller eq 'html') || + ($caller eq 'plaintext')) { # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this. + my %form = ( + grade_symb => $symb, + grade_courseid => $cdom.'_'.$cnum, + grade_domain => $env{'user.domain'}, + grade_username => $env{'user.name'}, + grade_imsexport => 1, + ); + my $feedurl=&Apache::lonnet::clutter($url); + my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form); + if (ref($response)) { + if ($response->is_success) { + $content = $userview; + $content =~ s/\Qonchange="javascript:setSubmittedPart('\E[^\']+\Q');"\E//g; + $content =~ s/^\s*[\n\r]+$//; + if ($caller eq 'plaintext') { + my @lines = split(/[\n\r]+/,$content); + my @tosave; + my $foilcounter = 0; + my @alphabet = ('a'..'z'); + my $mc_answer; + foreach my $line (@lines) { + next if ($line =~ /^\s*$/); + if ($line =~ m{(|\Q<\label>\E)\Q
Incorrect:\E)\Q
Correct:
}) { + $line =~ s/^(\s+|\s+)$//g; + $line =~ s{^\Q\E([^<]+)\Q\E$}{1}; + push(@tosave,$line); + } + $content = join("\t",@tosave); + if ($mc_answer) { + $content .= "\t".$mc_answer."\n"; + } + } + if (@tosave) { + $content = $currdirpath."\t".$title."\t".join("\t",@tosave); + if ($mc_answer) { + $content .= "\t".$mc_answer."\n"; + } + } + } else { + $content = ''.$content.''; + } + if (($caller eq 'plaintext') && ($testbank)) { + print $testbank $content; + } + } else { + $content = 'Not the owner of this resource'; + } + } else { + $content = 'Not the owner of this resource'; + } $repstatus = 'ok'; - $content = 'Not the owner of this resource'; } if ($repstatus eq 'ok') { print $copiedfile $content; @@ -905,7 +1004,6 @@ $repstatus = 'ok'; } } elsif ($caller eq 'uploaded') { - $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode); } if ($repstatus eq 'ok') { Index: loncom/homework/structuretags.pm diff -u loncom/homework/structuretags.pm:1.489 loncom/homework/structuretags.pm:1.490 --- loncom/homework/structuretags.pm:1.489 Mon Jun 6 21:01:06 2011 +++ loncom/homework/structuretags.pm Mon Jul 4 13:01:57 2011 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.489 2011/06/06 21:01:06 www Exp $ +# $Id: structuretags.pm,v 1.490 2011/07/04 13:01:57 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1183,6 +1183,9 @@ } } } + if ($env{'form.grade_imsexport'}) { + $result = ''; + } } elsif ($target eq 'tex') { $result .= 'INSERTTEXFRONTMATTERHERE'; @@ -1321,7 +1324,8 @@ } } elsif ( ($target eq 'web' || $target eq 'tex') && $Apache::inputtags::part eq '0' && - $status ne 'UNCHECKEDOUT' && $status ne 'NOT_YET_VIEWED') { + $status ne 'UNCHECKEDOUT' && $status ne 'NOT_YET_VIEWED' + && !$env{'form.grade_imsexport'}) { # if part is zero, no s existed, so we need show the current # grading status my $gradestatus = &Apache::inputtags::gradestatus($Apache::inputtags::part,$target); @@ -1331,8 +1335,9 @@ (($target eq 'web') && ($env{'request.state'} ne 'construct')) || ($target eq 'answer') || ($target eq 'tex') ) { - if ($target ne 'tex' && - $env{'form.answer_output_mode'} ne 'tex') { + if (($target ne 'tex') && + ($env{'form.answer_output_mode'} ne 'tex') && + (!$env{'form.grade_imsexport'})) { $result.=""; } if ($target eq 'web') { @@ -2055,7 +2060,8 @@ !$hidden && $in_order_show) { my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part, $target); - if ($Apache::lonhomework::type eq 'exam' && $target eq 'tex') { + if (($Apache::lonhomework::type eq 'exam' && $target eq 'tex') || + ($env{'form.grade_imsexport'})) { $gradestatus=''; } $result.=$gradestatus; Index: loncom/homework/lonhomework.pm diff -u loncom/homework/lonhomework.pm:1.326 loncom/homework/lonhomework.pm:1.327 --- loncom/homework/lonhomework.pm:1.326 Mon Jun 6 16:48:39 2011 +++ loncom/homework/lonhomework.pm Mon Jul 4 13:01:57 2011 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.326 2011/06/06 16:48:39 www Exp $ +# $Id: lonhomework.pm,v 1.327 2011/07/04 13:01:57 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -376,7 +376,12 @@ $date=&mt("can not be accessed from your location."); return($status,$date); } - + if ($env{'form.grade_imsexport'}) { + if (($env{'request.course.id'}) && + (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) { + return ('SHOW_ANSWER'); + } + } foreach my $temp ("opendate","duedate","answerdate") { $lastdate = $date; if ($temp eq 'duedate') {