--- loncom/interface/londocs.pm 2011/05/27 19:02:16 1.453 +++ 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.453 2011/05/27 19:02:16 raeburn Exp $ +# $Id: londocs.pm,v 1.465 2011/11/27 21:04:19 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -176,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++) { @@ -280,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'). @@ -310,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) { @@ -331,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 @@ -435,6 +438,8 @@ sub exportcourse { 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 @@ 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.
' ; @@ -580,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; @@ -619,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; @@ -656,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; @@ -905,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') { @@ -1472,7 +1577,7 @@ sub handle_edit_cmd { if ($cmd eq 'del') { if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) && - ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) { + ($url!~/$LONCAPA::assess_page_seq_re/)) { &Apache::lonnet::removeuploadedurl($url); } else { &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]); @@ -1508,7 +1613,8 @@ sub handle_edit_cmd { } sub editor { - my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype)=@_; + my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype, + $supplementalflag,$orderhash)=@_; my $container= ($env{'form.pagepath'}) ? 'page' : 'sequence'; @@ -1637,7 +1743,7 @@ sub editor { $r->print(''); } - my $output; + my ($to_show,$output); &Apache::loncommon::start_data_table_count(); #setup a row counter foreach my $res (@LONCAPA::map::order) { @@ -1654,30 +1760,38 @@ sub editor { &Apache::loncommon::end_data_table_count(); if ($shown) { - $r->print(&Apache::loncommon::start_scrollbox('900px','880px','400px') - .&Apache::loncommon::start_data_table()); + $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll') + .&Apache::loncommon::start_data_table(undef,'contentlist'); if ($allowed) { - $r->print(&Apache::loncommon::start_data_table_header_row() + $to_show .= &Apache::loncommon::start_data_table_header_row() .''.&mt('Move').'' .''.&mt('Actions').'' - .''.&mt('Document').''); + .''.&mt('Document').''; if ($folder !~ /^supplemental/) { - $r->print(''.&mt('Settings').''); + $to_show .= ''.&mt('Settings').''; } - $r->print(&Apache::loncommon::end_data_table_header_row()); + $to_show .= &Apache::loncommon::end_data_table_header_row(); } - $r->print($output + $to_show .= $output.' ' .&Apache::loncommon::end_data_table() - .&Apache::loncommon::end_scrollbox() - ); + .'
' + .&Apache::loncommon::end_scrollbox(); } else { - $r->print('

' + $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll') + .'

' .&mt('Currently no documents.') - .'

' - ); + .'
' + .&Apache::loncommon::end_scrollbox(); + } + my $tid = 1; + if ($supplementalflag) { + $tid = 2; } if ($allowed) { + $r->print(&generate_edit_table($tid,$orderhash,$to_show)); &print_paste_buffer($r,$container); + } else { + $r->print($to_show); } return; } @@ -1707,7 +1821,7 @@ sub process_file_upload { $LONCAPA::map::resources[1]=''; } if ($fatal) { - $$upload_output = '

'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'

'; + $$upload_output = '
'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'
'; return; } my $destination = 'docs/'; @@ -1733,7 +1847,7 @@ sub process_file_upload { } else { my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$}); - $$upload_output = '

'.&mt('Unable to save file [_1].',''.$filename.'').'

'; + $$upload_output = '
'.&mt('Unable to save file [_1].',''.$filename.'').'
'; return; } my $ext='false'; @@ -1752,7 +1866,7 @@ sub process_file_upload { ($errtext,$fatal)=&storemap($coursenum,$coursedom, $folder.'.'.$container); if ($fatal) { - $$upload_output = '

'.$errtext.'

'; + $$upload_output = '
'.$errtext.'
'; return; } else { if ($parseaction eq 'parse' && $mimetype eq 'text/html') { @@ -1779,6 +1893,7 @@ sub process_file_upload { } else { $$upload_output .= &mt('No embedded items identified').'
'; } + $$upload_output = '
'.$$upload_output.'
'; } } } @@ -2105,14 +2220,13 @@ END $form_start $form_end - - +
$form_start $form_end - $form_start $rand_order_text $form_end - $form_start $parameterset $form_end + $form_start $parameterset $form_end
+ $form_start $rand_order_text $form_end ENDPARMS } $line.=&Apache::loncommon::end_data_table_row(); @@ -2517,7 +2631,7 @@ ENDHEADERS $r->print(' '.&mt('Diffs').''); + '" target="diffs">'.&mt('Diffs').''); } $r->print('
'); if (++$entries_count % $entries_per_col == 0) { @@ -2647,15 +2761,15 @@ sub startContentScreen { if ($allowed) { $r->print('
  •       '.&mt('Content Editor').'      
  • '); + ' id="tabbededitor">      '.&mt('Content Editor').'      '); } $r->print('     '.&mt('Content Search').'     '); $r->print('      '.&mt('Content Index').'      '); $r->print('
  • '.&mt('Supplemental Documents').'
  • '); $r->print(''); - $r->print('
    ' - .'
    '); + $r->print('
    ' + .'
    '); $r->print('
    '); } @@ -2754,15 +2868,28 @@ sub handler { my $script=''; my $showdoc=0; + my $addentries = {}; my $containertag; my $uploadtag; +# Do we directly jump somewhere? + if ($env{'form.command'} eq 'direct') { + (my $mapurl) = &Apache::lonnet::decode_symb($env{'form.symb'}); + my $maptitle = &Apache::lonnet::gettitle($mapurl); + $mapurl=~s{^.*/([^/]+)\.\w+$}{$1}; + $env{'form.folderpath'}= + 'default&'.&Apache::lonhtmlcommon::entity_encode('Main Course Documents'). + '&default&...::::&'. + &Apache::lonhtmlcommon::entity_encode($mapurl).'&'. + &Apache::lonhtmlcommon::entity_encode($maptitle).'::::'; + } + # Where do we store these for when we come back? my $stored_folderpath='docs_folderpath'; if ($supplementalflag) { $stored_folderpath='docs_sup_folderpath'; } - + # No folderpath, no pagepath, see if we have something stored if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) { &Apache::loncommon::restore_course_settings($stored_folderpath, @@ -2854,7 +2981,22 @@ sub handler { $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/"); if ($allowed) { - $script .= &editing_js($udom,$uname); + my @tabids; + if ($supplementalflag) { + @tabids = ('002','ee2','ff2'); + } else { + @tabids = ('aa1','bb1','cc1','ff1'); + unless ($env{'form.pagepath'}) { + unshift(@tabids,'001'); + push(@tabids,('dd1','ee1')); + } + } + my $tabidstr = join("','",@tabids); + $script .= &editing_js($udom,$uname). + &resize_contentdiv_js($tabidstr); + $addentries = { + onload => "javascript:resize_contentdiv('contentscroll','1','1');", + }; } # -------------------------------------------------------------------- Body tag $script = '