--- loncom/interface/londocs.pm 2006/11/28 15:03:19 1.258 +++ loncom/interface/londocs.pm 2008/09/04 17:07:28 1.309 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.258 2006/11/28 15:03:19 www Exp $ +# $Id: londocs.pm,v 1.309 2008/09/04 17:07:28 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,7 +42,7 @@ use HTML::Entities; use GDBM_File; use Apache::lonlocal; use Cwd; -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); my $iconpath; @@ -99,7 +99,7 @@ sub authorhosts { $ca=$env{'user.name'}; $cd=$env{'user.domain'}; } else { - ($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/); + ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/); } my $allowed=0; my $myhome=&Apache::lonnet::homeserver($ca,$cd); @@ -122,16 +122,17 @@ 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'). + '
'; } } @@ -199,9 +200,9 @@ sub dumpcourse { $fail=1; } if ($fail) { - $r->print('fail'); + $r->print(''.&mt('fail').''); } else { - $r->print('ok'); + $r->print(''.&mt('ok').''); } } } else { @@ -235,7 +236,6 @@ sub dumpcourse { my ($ext)=($_=~/\.(\w+)$/); my $title=$hash{'title_'.$hash{ 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}}; - $title=~s/:/:/g; $r->print(''.($title?$title:' ').''); if (!$title) { $title=$_; @@ -258,10 +258,10 @@ sub dumpcourse { 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 { @@ -366,7 +366,7 @@ sub exportcourse { if (ref($curRes)) { my $symb = $curRes->symb(); my $ressymb = $symb; - if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) { + if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) { unless ($ressymb =~ m|adm/wrapper/adm|) { $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard'; } @@ -380,7 +380,7 @@ sub exportcourse { } $display .= ' />'."\n"; for (my $i=0; $i<$depth; $i++) { - $display .= ''."\n"; + $display .= ''."\n"; } if ($curRes->is_sequence()) { $display .= ' '."\n"; @@ -613,7 +613,7 @@ sub build_package { if (grep/^$count$/,@$discussions) { my $ressymb = $symb; my $mode; - if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) { + if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) { unless ($ressymb =~ m|adm/wrapper/adm|) { $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard'; } @@ -698,7 +698,7 @@ sub process_content { } } elsif ($symb =~ m-lib/templates/examupload\.problem$-) { $content_type = 'examupload'; - } elsif ($symb =~ m-adm/(\w+)/(\w+)/(\d+)/bulletinboard$-) { + } elsif ($symb =~ m-adm/($match_domain)/($match_username)/(\d+)/bulletinboard$-) { $content_type = 'bulletinboard'; my $contents = &Apache::imsexport::templatedpage($content_type,$3,$count,\@uploads,$1,$2); if ($contents) { @@ -818,7 +818,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#([^/]+)$#) { @@ -905,15 +905,14 @@ 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/$coursedom/$coursenum/(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". @@ -933,21 +932,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=~/^http:\/\//) { $ext = 'true'; } - $url =~ s/:/\:/g; - $name =~ s/:/\:/g; - $LONCAPA::map::resources[$idx] = - join ':', ($name, $url, $ext, 'normal', 'res'); + if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; } + $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 +960,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 { @@ -1028,7 +1034,8 @@ sub log_docs { sub log_differences { my ($plain)=@_; - my %storehash=('folder' => $plain); + my %storehash=('folder' => $plain, + 'currentfolder' => $env{'form.folder'}); if ($parmidx) { $storehash{'parameter_res'}=$oldresources[$parmidx]; foreach my $parm (keys %parmaction) { @@ -1063,9 +1070,9 @@ sub log_docs { # sub docs_change_log { my ($r)=@_; + my $folder=$env{'form.folder'}; $r->print(&Apache::loncommon::start_page('Course Document Change Log')); $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log')); - my %docslog=&Apache::lonnet::dump('nohist_docslog', $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'}); @@ -1084,14 +1091,11 @@ sub docs_change_log { my %lt=('hiddenresource' => 'Resources hidden', 'encrypturl' => 'URL hidden', 'randompick' => 'Randomly pick', + 'randomorder' => 'Randomly ordered', 'set' => 'set to', 'del' => 'deleted'); - - my $countselect = - &Apache::lonmeta::selectbox('show',$env{'form.show'},undef, - (&mt('all'),10,20,50,100,1000,10000)); - - $r->print(''.&mt('[_1] Records',$countselect).''. + $r->print(&Apache::loncommon::display_filter(). + ''. ''); $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row(). ''.&mt('Time').''.&mt('User').''.&mt('Folder').''.&mt('Before').''. @@ -1099,7 +1103,18 @@ sub docs_change_log { &Apache::loncommon::end_data_table_header_row()); my $shown=0; foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) { + if ($env{'form.displayfilter'} eq 'currentfolder') { + if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; } + } my @changes=keys(%{$docslog{$id}{'logentry'}}); + if ($env{'form.displayfilter'} eq 'containing') { + my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'. + &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'}); + foreach my $key (@changes) { + $wholeentry.=':'.$docslog{$id}{'logentry'}{$key}; + } + if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; } + } my $count = 0; my $time = &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'}); @@ -1146,7 +1161,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)); } } @@ -1159,7 +1174,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]).':