--- loncom/interface/londocs.pm 2008/12/15 06:32:01 1.323 +++ loncom/interface/londocs.pm 2009/09/02 16:24:28 1.385 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.323 2008/12/15 06:32:01 raeburn Exp $ +# $Id: londocs.pm,v 1.385 2009/09/02 16:24:28 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,6 +35,7 @@ use Apache::Constants qw(:common :http); use Apache::imsexport; use Apache::lonnet; use Apache::loncommon; +use Apache::lonhtmlcommon; use LONCAPA::map(); use Apache::lonratedt(); use Apache::lonxml; @@ -59,7 +60,6 @@ my $hadchanges; my %help=(); - sub mapread { my ($coursenum,$coursedom,$map)=@_; return @@ -73,7 +73,7 @@ sub storemap { &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'. $map,1); if ($errtext) { return ($errtext,2); } - + $hadchanges=1; return ($errtext,0); } @@ -120,11 +120,9 @@ sub dumpbutton { my $type = &Apache::loncommon::course_type(); if ($home+$other==0) { return ''; } if ($home) { - return '
'. - ''. - &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs'). - '
'; + 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. @@ -136,7 +134,7 @@ sub dumpbutton { sub clean { my ($title)=@_; $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs; - return $title; + return $title; } @@ -145,7 +143,7 @@ sub dumpcourse { my ($r) = @_; my $type = &Apache::loncommon::course_type(); $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space'). - '
'); + ''); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$type.' DOCS to Construction Space')); my ($home,$other,%outhash)=&authorhosts(); unless ($home) { return ''; } @@ -178,8 +176,8 @@ sub dumpcourse { my $fail=0; for (my $i=0;$i<$#dirs;$i++) { $makepath.='/'.$dirs[$i]; - unless (-e $makepath) { - unless(mkdir($makepath,0777)) { $fail=1; } + unless (-e $makepath) { + unless(mkdir($makepath,0777)) { $fail=1; } } } $r->print('
'.$item.' => '.$newfilename.': '); @@ -265,10 +263,8 @@ sub dumpcourse { sub exportbutton { my $type = &Apache::loncommon::course_type(); - return '
'. - ''. - &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'
'; + return "".&mt('IMS Export')."". + &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'
'; } @@ -280,6 +276,15 @@ sub exportcourse { $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); my $numdisc = keys(%discussiontime); my $navmap = Apache::lonnavmaps::navmap->new(); + if (!defined($navmap)) { + $r->print(&Apache::loncommon::start_page('Export '.$type.' 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'}); + return; + } my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef); my $curRes; my $outcome; @@ -293,7 +298,17 @@ sub exportcourse { my @exportitems = &Apache::loncommon::get_env_multiple('form.archive'); my @discussions = &Apache::loncommon::get_env_multiple('form.discussion'); if (@exportitems == 0 && @discussions == 0) { - $outcome = '
As you did not select any content items or discussions for export, an IMS package has not been created. Please go back to select either content items or discussions for export'; + $outcome = + '

' + .&mt('As you did not select any content items or discussions' + .' for export, an IMS package has not been created.') + .'

' + .'

' + .&mt('Please [_1]go back[_2] to select either content items' + .' or discussions for export.' + ,'' + ,'') + .'

'; } else { my $now = time; my %symbs; @@ -316,35 +331,51 @@ sub exportcourse { open(OUTPUT, "zip -r $imszip * 2> /dev/null |"); close(OUTPUT); chdir $cwd; - $outcome .= &mt('Download the zip file from IMS '.lc($type).' archive
',$imszipfile,); if ($copyresult) { - $outcome .= &mt('The following errors occurred during export - [_1]',$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, because there was a problem creating a manifest file.').'
'; + $outcome = '

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

' + .'

' + .&mt('Go Back') + .'

'; } } - $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package')); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package')); + $r->print(&Apache::loncommon::start_page('Export '.$type.' 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 .= ''. - ''. - ''. - ''. - '
 Content items'. - ''; + $display .= '
'. + ''.&mt('Content items').''. + ''. - '  
  
 Discussion posts'. - '
'. + '
'. + ''.&mt('Discussion posts').''. + ''. - '  
'; + '  '. + '
'; my $curRes; my $depth = 0; my $count = 0; @@ -353,13 +384,17 @@ sub exportcourse { my %parent = (); my %children = (); my $lastcontainer = $startcount; - my @bgcolors = ('#F6F6F6','#FFFFFF'); - $display .= ''. - '' + .''; + $display .= '' + .&Apache::loncommon::end_data_table_header_row(); while ($curRes = $it->next()) { if (ref($curRes)) { $count ++; @@ -380,39 +415,46 @@ sub exportcourse { $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard'; } } - my $color = $count%2; - $display .=''; + $display .= ' '.$curRes->title().''."\n"; + + # Existing discussion posts? if ($discussiontime{$ressymb} > 0) { $boards ++; $currelem = $count+$boards+$startcount; - $display .= ''."\n"; + $display .= ''."\n"; } else { - $display .= ''."\n"; + $display .= ''."\n"; } + $display .= &Apache::loncommon::end_data_table_row(); } } + $display .= &Apache::loncommon::end_data_table(); my $scripttag = qq| - |; - $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package', + $r->print(&Apache::loncommon::start_page('Export '.$type.' to IMS Package', $scripttag)); - $r->print(&Apache::lonhtmlcommon::breadcrumbs('Export '.lc($type).' to IMS content package')); - $r->print($display.'
Export content item?
 '."\n"; + $display .= &Apache::loncommon::start_data_table() + .&Apache::loncommon::start_data_table_header_row() + .''.&mt('Export content item?').''; if ($numdisc > 0) { - $display.='Export discussion posts?'."\n"; + $display .= &mt('Export discussion posts?'); + } else { + $display .= ' '; } - $display.=' 
'."\n". - ''."\n" + .'is_sequence()) || ($curRes->is_page())) { my $checkitem = $count + $boards + $startcount; - $display .= 'onClick="javascript:propagateCheck('."'$checkitem'".')"'; + $display .= 'onclick="javascript:propagateCheck('."'$checkitem'".')"'; } $display .= ' />'."\n"; for (my $i=0; $i<$depth; $i++) { - $display .= ''."\n"; + $display .= '' + .''."\n"; } if ($curRes->is_sequence()) { - $display .= ' '."\n"; + $display .= ' '."\n"; $lastcontainer = $count + $startcount + $boards; } elsif ($curRes->is_page()) { - $display .= ' '."\n"; + $display .= ' '."\n"; $lastcontainer = $count + $startcount + $boards; } my $currelem = $count+$boards+$startcount; $children{$parent{$depth}} .= $currelem.':'; - $display .= ' '.$curRes->title().'  ' + .'' + .'  
'. - '

'. + $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export')); + $r->print($display. + '

'. '

'. - &Apache::loncommon::end_page()); + &mt('Export').'" />

'); } } @@ -755,7 +796,7 @@ sub replicate_content { if ($caller eq 'templateupload') { $url = $symb; $url =~ s#//#/#g; - } else { + } else { ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); } my $content; @@ -795,9 +836,9 @@ sub replicate_content { $$message = 'Could not render '.$url.' server message - '.$rtncode."
\n"; } } elsif ($caller eq 'noedit') { -# Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this. +# Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this. $repstatus = 'ok'; - $content = 'Not the owner of this resource'; + $content = 'Not the owner of this resource'; } if ($repstatus eq 'ok') { print $copiedfile $content; @@ -848,14 +889,14 @@ sub extract_media { } } if ($caller eq 'resource') { - my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res'; - my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url); + my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res'; + my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url); $embed_content = &Apache::lonnet::getfile($embed_path); unless ($embed_content eq -1) { $repstatus = 'ok'; } } elsif ($caller eq 'uploaded') { - + $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode); } if ($repstatus eq 'ok') { @@ -917,10 +958,10 @@ sub group_import { while (@files) { my ($name, $url, $residx) = @{ shift(@files) }; - if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) + if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) && ($caller eq 'londocs') && (!&Apache::lonnet::stat_file($url))) { - + my $errtext = ''; my $fatal = 0; my $newmapstr = ''."\n". @@ -940,7 +981,7 @@ sub group_import { } } if ($url) { - if (!$residx + if (!$residx || defined($LONCAPA::map::zombies[$residx])) { $residx = &LONCAPA::map::getresidx($url,$residx); push(@LONCAPA::map::order, $residx); @@ -949,7 +990,7 @@ sub group_import { if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; } $url = &LONCAPA::map::qtunescape($url); $name = &LONCAPA::map::qtunescape($name); - $LONCAPA::map::resources[$residx] = + $LONCAPA::map::resources[$residx] = join(':', ($name, $url, $ext, 'normal', 'res')); } } @@ -980,9 +1021,9 @@ sub breadcrumbs { my $url='/adm/coursedocs?folderpath='. &escape($folderpath); my $name=&unescape($foldername); -# randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername +# randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//; - if ($1 ne '') { + if ($1 ne '') { $randompick=$1; } else { $randompick=-1; @@ -1000,15 +1041,14 @@ sub breadcrumbs { &Apache::lonhtmlcommon::add_breadcrumb( {'href'=>$url.$cpinfo, 'title'=>$name, - 'text'=>''. - $name.'', + 'text'=>$name, 'no_mt'=>1, }); $plain.=$name.' > '; } $plain=~s/\>\;\s*$//; return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp', - 'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain,$is_random_order); + undef, undef, 1 ),$randompick,$ishidden,$isencrypted,$plain,$is_random_order); } sub log_docs { @@ -1121,7 +1161,7 @@ sub docs_change_log { foreach my $key (@changes) { $wholeentry.=':'.$docslog{$id}{'logentry'}{$key}; } - if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; } + if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; } } my $count = 0; my $time = @@ -1172,7 +1212,7 @@ sub docs_change_log { if ($oldname ne '' && $oldname ne $newname) { $r->print(&LONCAPA::map::qtescape($newname)); } - } + } $r->print('