--- loncom/interface/londocs.pm 2007/01/05 16:40:27 1.265 +++ loncom/interface/londocs.pm 2008/12/10 21:46:58 1.318 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.265 2007/01/05 16:40:27 albertel Exp $ +# $Id: londocs.pm,v 1.318 2008/12/10 21:46:58 kaisler Exp $ # # Copyright Michigan State University Board of Trustees # @@ -26,6 +26,8 @@ # http://www.lon-capa.org/ # + + package Apache::londocs; use strict; @@ -53,15 +55,10 @@ my %alreadyseen=(); my $hadchanges; -# Available help topics my %help=(); -# Mapread read maps into LONCAPA::map:: global arrays -# @order and @resources, determines status -# sets @order - pointer to resources in right order -# sets @resources - array with the resources with correct idx -# + sub mapread { my ($coursenum,$coursedom,$map)=@_; @@ -81,7 +78,7 @@ sub storemap { return ($errtext,0); } -# ----------------------------------------- Return hash with valid author names + sub authorhosts { my %outhash=(); @@ -116,22 +113,23 @@ sub authorhosts { } return ($home,$other,%outhash); } -# ------------------------------------------------------ Generate "dump" button + sub dumpbutton { my ($home,$other,%outhash)=&authorhosts(); my $type = &Apache::loncommon::course_type(); if ($home+$other==0) { return ''; } - my $output=''; if ($home) { - return ''. + return '
'. ''. - &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs'); + &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs'). + '
'; } else { - return''. + return '
'. &mt('Dump '.$type. - ' DOCS to Construction Space: available on other servers'); + ' DOCS to Construction Space: available on other servers'). + '
'; } } @@ -140,7 +138,8 @@ sub clean { $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs; return $title; } -# -------------------------------------------------------- Actually dump course + + sub dumpcourse { my ($r) = @_; @@ -199,9 +198,9 @@ sub dumpcourse { $fail=1; } if ($fail) { - $r->print('fail'); + $r->print(''.&mt('fail').''); } else { - $r->print('ok'); + $r->print(''.&mt('ok').''); } } } else { @@ -227,15 +226,22 @@ sub dumpcourse { my $title=$origcrsdata{'description'}; $title=~s/[\/\s]+/\_/gs; $title=&clean($title); - $r->print('

'.&mt('Folder in Construction Space').'


'); + $r->print('

'.&mt('Folder in Construction Space').'

' + .'
'); &tiehash(); - $r->print('

'.&mt('Filenames in Construction Space').'

'); + $r->print('

'.&mt('Filenames in Construction Space').'

' + .&Apache::loncommon::start_data_table() + .&Apache::loncommon::start_data_table_header_row() + .'' + .'' + .'' + .&Apache::loncommon::end_data_table_header_row()); foreach (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) { - $r->print(''); + $r->print(&Apache::loncommon::start_data_table_row() + .''); my ($ext)=($_=~/\.(\w+)$/); my $title=$hash{'title_'.$hash{ 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}}; - $title=~s/:/:/g; $r->print(''); if (!$title) { $title=$_; @@ -245,25 +251,28 @@ sub dumpcourse { $title=~s/\.(\w+)$//; $title=&clean($title); $title.='.'.$ext; - $r->print("\n\n"); + $r->print("\n" + .&Apache::loncommon::end_data_table_row()); } - $r->print("
'.&mt('Internal Filename').''.&mt('Title').''.&mt('Save as ...').'
'.&mt('Internal Filename').''.&mt('Title').''.&mt('Save as ...').'
'.$_.''.$_.''.($title?$title:' ').'
\n"); + $r->print(&Apache::loncommon::end_data_table()); &untiehash(); $r->print( - '

'); + '

'); } } -# ------------------------------------------------------ Generate "export" button + sub exportbutton { my $type = &Apache::loncommon::course_type(); - return ''. + return '
'. ''. - &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs'); + &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'
'; } + + sub exportcourse { my $r=shift; my $type = &Apache::loncommon::course_type(); @@ -309,10 +318,10 @@ sub exportcourse { chdir $cwd; $outcome .= &mt('Download the zip file from IMS '.lc($type).' archive
',$imszipfile,); if ($copyresult) { - $outcome .= 'The following errors occurred during export - '.$copyresult; + $outcome .= &mt('The following errors occurred during export - [_1]',$copyresult); } } else { - $outcome = '
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.').'
'; } } $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package')); @@ -380,7 +389,7 @@ sub exportcourse { } $display .= ' />'."\n"; for (my $i=0; $i<$depth; $i++) { - $display .= ''."\n"; + $display .= ''."\n"; } if ($curRes->is_sequence()) { $display .= ' '."\n"; @@ -818,7 +827,7 @@ sub extract_media { $dirpath = $url; $container = ''; } - &Apache::lonnet::extract_embedded_items(undef,undef,\%allfiles,\%codebase,$content); + &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,$content); foreach my $embed_file (keys(%allfiles)) { my $filename; if ($embed_file =~ m#([^/]+)$#) { @@ -902,18 +911,16 @@ sub store_template { } } -# Imports the given (name, url) resources into the course -# coursenum, coursedom, and folder must precede the list + sub group_import { - my $coursenum = shift; - my $coursedom = shift; - my $folder = shift; - my $container = shift; - my $caller = shift; - while (@_) { - my $name = shift; - my $url = shift; - if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) && ($caller eq 'londocs')) { + my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_; + + while (@files) { + my ($name, $url, $residx) = @{ shift(@files) }; + 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". @@ -925,7 +932,7 @@ sub group_import { my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom, 'output',$1.$2); if ($result != m|^/uploaded/|) { - $errtext.='Map not saved: A network error occured when trying to save the new map. '; + $errtext.='Map not saved: A network error occurred when trying to save the new map. '; $fatal = 2; } if ($fatal) { @@ -933,21 +940,24 @@ sub group_import { } } if ($url) { - my $idx = &LONCAPA::map::getresidx($url); - $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx; + if (!$residx + || defined($LONCAPA::map::zombies[$residx])) { + $residx = &LONCAPA::map::getresidx($url,$residx); + push(@LONCAPA::map::order, $residx); + } my $ext = 'false'; if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; } - $url =~ s/:/\:/g; - $name =~ s/:/\:/g; - $LONCAPA::map::resources[$idx] = - join ':', ($name, $url, $ext, 'normal', 'res'); + $url = &LONCAPA::map::qtunescape($url); + $name = &LONCAPA::map::qtunescape($name); + $LONCAPA::map::resources[$residx] = + join(':', ($name, $url, $ext, 'normal', 'res')); } } return &storemap($coursenum, $coursedom, $folder.'.'.$container); } sub breadcrumbs { - my ($where)=@_; + my ($where,$allowed,$type)=@_; &Apache::lonhtmlcommon::clear_breadcrumbs(); my (@folders); if ($env{'form.pagepath'}) { @@ -958,43 +968,47 @@ sub breadcrumbs { my $folderpath; my $cpinfo=''; my $plain=''; - if ($env{'form.markedcopy_url'}) { - $cpinfo='&markedcopy_url='. - &escape($env{'form.markedcopy_url'}). - '&markedcopy_title='. - &escape($env{'form.markedcopy_title'}); - } my $randompick=-1; my $isencrypted=0; my $ishidden=0; + my $is_random_order=0; while (@folders) { my $folder=shift(@folders); - my $foldername=shift(@folders); + my $foldername=shift(@folders); if ($folderpath) {$folderpath.='&';} $folderpath.=$folder.'&'.$foldername; my $url='/adm/coursedocs?folderpath='. &escape($folderpath); - my $name=&unescape($foldername); -# randompick number, hidden, encrypted is appended with ":"s to the foldername - $name=~s/\:(\d*)\:(\w*)\:(\w*)$//; - if ($1 ne '') { + my $name=&unescape($foldername); +# randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername + $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//; + if ($1 ne '') { $randompick=$1; } else { $randompick=-1; } if ($2) { $ishidden=1; } 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'); + } + } &Apache::lonhtmlcommon::add_breadcrumb( {'href'=>$url.$cpinfo, 'title'=>$name, 'text'=>''. - $name.'' + $name.'', + 'no_mt'=>1, }); $plain.=$name.' > '; } $plain=~s/\>\;\s*$//; return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp', - 'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain); + 'LC_docs_path'),$randompick,$ishidden,$isencrypted,$plain,$is_random_order); } sub log_docs { @@ -1059,9 +1073,9 @@ sub log_docs { } -# -# Docs Change Log -# + + + sub docs_change_log { my ($r)=@_; my $folder=$env{'form.folder'}; @@ -1085,6 +1099,7 @@ sub docs_change_log { my %lt=('hiddenresource' => 'Resources hidden', 'encrypturl' => 'URL hidden', 'randompick' => 'Randomly pick', + 'randomorder' => 'Randomly ordered', 'set' => 'set to', 'del' => 'deleted'); $r->print(&Apache::loncommon::display_filter(). @@ -1154,7 +1169,7 @@ sub docs_change_log { for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) { my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0]; my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0]; - if ($oldname ne $newname) { + if ($oldname ne '' && $oldname ne $newname) { $r->print(&LONCAPA::map::qtescape($newname)); } } @@ -1167,7 +1182,7 @@ sub docs_change_log { $r->print(''); if ($docslog{$id}{'logentry'}{'parameter_res'}) { $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':