--- loncom/interface/londocs.pm 2009/08/28 19:43:16 1.384 +++ loncom/interface/londocs.pm 2011/11/27 22:51:28 1.466 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.384 2009/08/28 19:43:16 raeburn Exp $ +# $Id: londocs.pm,v 1.466 2011/11/27 22:51:28 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -117,17 +117,22 @@ sub authorhosts { sub dumpbutton { my ($home,$other,%outhash)=&authorhosts(); - my $type = &Apache::loncommon::course_type(); + my $crstype = &Apache::loncommon::course_type(); if ($home+$other==0) { return ''; } if ($home) { - my $link = "".&mt('Dump '.$type.' DOCS to Construction Space').""; - return $link.' '. - &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs').'
'; - } else { - return '
'. - &mt('Dump '.$type. - ' 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'); } } @@ -141,10 +146,10 @@ sub clean { sub dumpcourse { my ($r) = @_; - my $type = &Apache::loncommon::course_type(); - $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space'). + my $crstype = &Apache::loncommon::course_type(); + $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Documents to Construction Space'). '
'); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$type.' 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,15 +260,15 @@ sub dumpcourse { $r->print(&Apache::loncommon::end_data_table()); &untiehash(); $r->print( - '

'); + '

'); } } sub exportbutton { - my $type = &Apache::loncommon::course_type(); - return "".&mt('IMS Export')."". + my $crstype = &Apache::loncommon::course_type(); + return "".&mt('IMS Export')."". &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'
'; } @@ -271,18 +276,29 @@ sub exportbutton { sub exportcourse { my $r=shift; - my $type = &Apache::loncommon::course_type(); + 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 '.$type.' to IMS Package'). + $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package'). '

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

'. - '
'. - &mt('Unable to retrieve information about course contents'). - '
'.&mt('Return to Course Editor').''); - &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'}); + '
'); + 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'}); return; } my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef); @@ -295,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) { @@ -316,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 @@ -331,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.') .'

' @@ -353,29 +371,31 @@ sub exportcourse { .'

'; } } - $r->print(&Apache::loncommon::start_page('Export '.$type.' to IMS Package')); + $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package')); $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export')); $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 '.$type.'.') - .'

'; - $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; @@ -386,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 ++; @@ -415,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(); @@ -507,9 +521,19 @@ function containerCheck(item) { // ]]> |; - $r->print(&Apache::loncommon::start_page('Export '.$type.' to IMS Package', + $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.
' ; @@ -571,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; @@ -610,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; @@ -647,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; @@ -896,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') { @@ -998,7 +1112,7 @@ sub group_import { } sub breadcrumbs { - my ($where,$allowed,$type)=@_; + my ($allowed,$crstype)=@_; &Apache::lonhtmlcommon::clear_breadcrumbs(); my (@folders); if ($env{'form.pagepath'}) { @@ -1013,6 +1127,15 @@ sub breadcrumbs { my $isencrypted=0; my $ishidden=0; my $is_random_order=0; + if (!$allowed) { + my $description = $env{'course.'.$env{'request.course.id'}.'.description'}; + &Apache::lonhtmlcommon::add_breadcrumb( + {'href' => '/adm/menu', + 'title'=> 'Go to main menu', + 'text' => $description, + }); + $plain .= $description.' >'; + } while (@folders) { my $folder=shift(@folders); my $foldername=shift(@folders); @@ -1032,11 +1155,7 @@ sub breadcrumbs { if ($3) { $isencrypted=1; } if ($4 ne '') { $is_random_order = 1; } if ($folder eq 'supplemental') { - if ($allowed) { - $name = &mt('Supplemental '.$type.' Documents'); - } else { - $name = &mt($type.' Documents'); - } + $name = &mt('Supplemental '.$crstype.' Documents'); } &Apache::lonhtmlcommon::add_breadcrumb( {'href'=>$url.$cpinfo, @@ -1136,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', @@ -1224,6 +1344,7 @@ sub docs_change_log { $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':