--- loncom/interface/londocs.pm 2009/11/02 12:10:34 1.410 +++ loncom/interface/londocs.pm 2011/11/27 21:04:19 1.465 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.410 2009/11/02 12:10:34 wenzelju Exp $ +# $Id: londocs.pm,v 1.465 2011/11/27 21:04:19 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -120,14 +120,19 @@ sub dumpbutton { my $crstype = &Apache::loncommon::course_type(); if ($home+$other==0) { return ''; } if ($home) { - my $link = "".&mt('Dump '.$crstype.' DOCS to Construction Space').""; - return $link.' '. - &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs').'
'; - } else { - return '
'. - &mt('Dump '.$crstype. - ' DOCS to Construction Space: available on other servers'). - '
'; + my $link = + "" + .&mt('Dump '.$crstype.' Documents to Construction Space') + .''; + return + $link.' ' + .&Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs') + .'
'; + } else { + return + &mt('Dump '.$crstype.' Documents to Construction Space: available on other servers'); } } @@ -142,9 +147,9 @@ sub clean { sub dumpcourse { my ($r) = @_; my $crstype = &Apache::loncommon::course_type(); - $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' DOCS to Construction Space'). + $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Documents to Construction Space'). '
'); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' DOCS to Construction Space')); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' Documents to Construction Space')); my ($home,$other,%outhash)=&authorhosts(); unless ($home) { return ''; } my $origcrsid=$env{'request.course.id'}; @@ -171,7 +176,7 @@ sub dumpcourse { $newfilename=&clean($newfilename); $newfilename.='.'.$ext; my @dirs=split(/\//,$newfilename); - my $path='/home/'.$ca.'/public_html'; + my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca"; my $makepath=$path; my $fail=0; for (my $i=0;$i<$#dirs;$i++) { @@ -255,7 +260,7 @@ sub dumpcourse { $r->print(&Apache::loncommon::end_data_table()); &untiehash(); $r->print( - '

'); + '

'); } } @@ -263,7 +268,7 @@ sub dumpcourse { sub exportbutton { my $crstype = &Apache::loncommon::course_type(); - return "".&mt('IMS Export')."". + return "".&mt('IMS Export')."". &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'
'; } @@ -275,6 +280,7 @@ sub exportcourse { 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'). @@ -305,6 +311,7 @@ sub exportcourse { &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) { @@ -326,9 +333,10 @@ sub exportcourse { 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 @@ -341,20 +349,20 @@ sub exportcourse { open(OUTPUT, "zip -r $imszip * 2> /dev/null |"); close(OUTPUT); chdir $cwd; + $outcome .= '

' + .&mt('[_1]Your IMS package[_2] is ready for download.' + ,'','') + .'

'; if ($copyresult) { $outcome .= '

' .&mt('The following errors occurred during export - [_1]' ,$copyresult) .'

'; } - $outcome .= '

' - .&mt('[_1]Your IMS package[_2] is ready for download.' - ,'','') - .'

'; } else { $outcome = '

' .&mt('Unfortunately you will not be able to retrieve' - .' an IMS archive of this posts at this time,' + .' an IMS archive of your course at this time,' .' because there was a problem creating a' .' manifest file.') .'

' @@ -368,24 +376,26 @@ sub exportcourse { $r->print($outcome); $r->print(&Apache::loncommon::end_page()); } else { - my $display; - $display = '
'."\n"; - $display .= '

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

'; - $display .= '
'. + my $display=''."\n". + '

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

'. + '
'. ''.&mt('Content items').''. ''. '  
'. - '
'. - ''.&mt('Discussion posts').''. - ''. - '  '. - '
'; + ' onclick="javascript:uncheckAll(document.exportdoc.archive)" />
'; + if ($numdisc > 0) { + $display .= '
'. + ''.&mt('Discussion posts').''. + ''. + '  '. + '
'; + } + $display .= '
'; my $curRes; my $depth = 0; my $count = 0; @@ -396,15 +406,11 @@ sub exportcourse { my $lastcontainer = $startcount; $display .= &Apache::loncommon::start_data_table() .&Apache::loncommon::start_data_table_header_row() - .''.&mt('Export content item?').'' - .''; + .''.&mt('Export content item?').''; if ($numdisc > 0) { - $display .= &mt('Export discussion posts?'); - } else { - $display .= ' '; + $display .= ''.&mt('Export discussion posts?').''; } - $display .= '' - .&Apache::loncommon::end_data_table_header_row(); + $display .= &Apache::loncommon::end_data_table_header_row(); while ($curRes = $it->next()) { if (ref($curRes)) { $count ++; @@ -425,37 +431,35 @@ sub exportcourse { $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())) { - my $checkitem = $count + $boards + $startcount; - $display .= 'onclick="javascript:propagateCheck('."'$checkitem'".')"'; + $lastcontainer = $currelem; + $display .= 'onclick="javascript:propagateCheck('."'$currelem'".')"'; + } elsif ($curRes->is_problem()) { + $numprobs ++; } $display .= ' />'."\n"; for (my $i=0; $i<$depth; $i++) { - $display .= '' - .''."\n"; + $display .= ('' x2)."\n"; } if ($curRes->is_sequence()) { $display .= ' '."\n"; - $lastcontainer = $count + $startcount + $boards; } elsif ($curRes->is_page()) { $display .= ' '."\n"; - $lastcontainer = $count + $startcount + $boards; } - my $currelem = $count+$boards+$startcount; $children{$parent{$depth}} .= $currelem.':'; $display .= ' '.$curRes->title().''."\n"; # Existing discussion posts? if ($discussiontime{$ressymb} > 0) { $boards ++; - $currelem = $count+$boards+$startcount; $display .= '' .'' .''."\n"; - } else { + } elsif ($numdisc > 0) { $display .= ' '."\n"; } $display .= &Apache::loncommon::end_data_table_row(); @@ -520,6 +524,16 @@ function containerCheck(item) { $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.
' ; @@ -581,7 +599,8 @@ sub create_ims_store { } 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; @@ -620,6 +639,7 @@ sub build_package { $count = 0; my $imsresources; my $pkgdepth; + my $currdirpath = 'Top'; while ($curRes = $it->next()) { if ($curRes == $it->BEGIN_MAP()) { $prevdepth = $depth; @@ -657,10 +677,28 @@ sub build_package { ''.$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),$curRes->map_pc()) { + next if ($pc <= 1); + 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, + instructor_comments => 'hide', + ); + 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:\E(|\Q\E)\Q
\E}) { + $line =~ s/^(\s+|\s+)$//g; + $line =~ s{^\Q\E([^<]+)\Q\E$}{1}; + $tosave[$foilcounter] .= $line.' '; + } + $content = join("\t",@tosave); + if ($mc_answer) { + $content .= "\t".$mc_answer."\n"; + } + } + if (@tosave) { + my $qtype; + if ($mc_answer) { + $qtype = 'MC'; + } + $content = $currdirpath."\t".$title."\t$qtype\t".join("\t",@tosave); + if ($mc_answer) { + $content .= "\t".$mc_answer; + } + $content .= "\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; @@ -906,7 +1011,6 @@ sub extract_media { $repstatus = 'ok'; } } elsif ($caller eq 'uploaded') { - $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode); } if ($repstatus eq 'ok') { @@ -1151,6 +1255,7 @@ sub docs_change_log { &Apache::loncommon::restore_course_settings('docs_log', \%saveable_parameters); if (!$env{'form.show'}) { $env{'form.show'}=10; } +# FIXME: internationalization seems wrong here my %lt=('hiddenresource' => 'Resources hidden', 'encrypturl' => 'URL hidden', 'randompick' => 'Randomly pick', @@ -1239,6 +1344,7 @@ sub docs_change_log { $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':