--- loncom/interface/lonindexer.pm 2004/06/17 01:44:34 1.112 +++ loncom/interface/lonindexer.pm 2004/09/25 17:58:01 1.124 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Directory Indexer # -# $Id: lonindexer.pm,v 1.112 2004/06/17 01:44:34 www Exp $ +# $Id: lonindexer.pm,v 1.124 2004/09/25 17:58:01 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -60,7 +60,8 @@ my %hash; # global user-specific gdbm fi my %dirs; # keys are directories, values are the open/close status my %language; # has the reference information present in language.tab my %dynhash; # hash of hashes for dynamic metadata - +my %dynread; # hash of directories already read for dynamic metadata +my %fieldnames; # Metadata fieldnames # ----- Values which are set by the handler subroutine and are accessible to # ----- other methods. my $extrafield; # default extra table cell @@ -87,6 +88,7 @@ sub handler { # these global to this package? It is just so wrong....) undef (@Only); undef (@Omit); + %fieldnames=&Apache::lonmeta::fieldnames(); # ------------------------------------- read in machine configuration variables my $iconpath= $r->dir_config('lonIconsURL') . "/"; @@ -134,9 +136,10 @@ sub handler { if ($ENV{'form.launch'} eq '2') { $r->content_type('text/html'); my $extra=''; - if (defined($ENV{'form.titleelement'})) { + if (defined($ENV{'form.titleelement'}) && + $ENV{'form.titleelement'} ne '') { my $verify_title = &Apache::lonnet::gettitle($ENV{'form.acts'}); - &Apache::lonnet::logthis("Hrrm $ENV{'form.acts'} -- $verify_title"); +# &Apache::lonnet::logthis("Hrrm $ENV{'form.acts'} -- $verify_title"); $verify_title=~s/'/\\'/g; $extra='window.opener.document.forms["'.$ENV{'form.form'}.'"].elements["'.$ENV{'form.titleelement'}.'"].value=\''.$verify_title.'\';'; } @@ -176,7 +179,7 @@ END ' border="0" />'; $colspan=" colspan='2' "; my $cl=&mt('Close'); - my $gi=&mt('Group Import'); + my $gi=&mt('Import'); $closebutton=< END @@ -439,26 +442,30 @@ $r->print(&Apache::loncommon::bodytag('B 'av' => 'All versions', 'ud' => 'Update Display' ); - my $Displayfileattributes=&mt('Display file attributes'); $r->print(< -$Displayfileattributes
- - - - - - - - - - - - - - -
$lt{'ti'} $lt{'si'} $lt{'la'} $lt{'lm'} $lt{'st'} $lt{'sa'}
$lt{'au'} $lt{'kw'} $lt{'ln'} $lt{'sr'} $lt{'av'} $lt{'li'}
+ + + + + + + + + + + + + + + + + + + + +
 
@@ -511,15 +518,15 @@ END if ($hash{'display_attrs_5'} == 1); $r->print("".&mt("Language")."\n") if ($hash{'display_attrs_6'} == 1); - $r->print("".&mt("Resource")."\n") - if ($hash{'display_attrs_7'} == 1); $r->print("".&mt("Usage Statistics")."
(". - &mt("Courses/Network Hits").")
\n") + &mt("Courses/Network Hits").") ".&mt('updated periodically')."\n") if ($hash{'display_attrs_8'} == 1); $r->print("".&mt("Source Available")."\n") if ($hash{'display_attrs_10'} == 1); $r->print("".&mt("Linked/Related Resources")."\n") if ($hash{'display_attrs_11'} == 1); + $r->print("".&mt("Resource")."\n") + if ($hash{'display_attrs_7'} == 1); $r->print(''); # ----------------- read in what directories have previously been set to "open" @@ -655,10 +662,12 @@ sub get_list { if ($ENV{'form.updatedisplay'}) { foreach (keys %hash) { delete $hash{$_} if ($_ =~ /^dirlist_files_/); + delete $hash{$_} if ($_ =~ /^dirlist_timestamp_files_/); } } - if ($hash{'dirlist_files_'.$luri}) { + if (defined($hash{'dirlist_files_'.$luri}) && + $hash{'dirlist_timestamp_files_'.$luri}+600 > (time)) { @list = split(/\n/,$hash{'dirlist_files_'.$luri}); } elsif ($uri=~/\.(page|sequence)\/$/) { # is a page or a sequence @@ -674,7 +683,7 @@ sub get_list { # is really a directory @list = &Apache::lonnet::dirlist($uri); $hash{'dirlist_files_'.$luri} = join("\n",@list); - &dynmetaread($uri); + $hash{'dirlist_timestamp_files_'.$luri} = time; } return @list=&match_ext($r,@list); } @@ -682,9 +691,21 @@ sub get_list { sub dynmetaread { my $uri=shift; if (($hash{'display_attrs_8'}==1) || ($hash{'display_attrs_11'}==1)) { +# We don't want the filename + $uri=~s/\/[^\/]+$//; +# Did we already see this? + my $builddir=$uri; + while ($builddir) { + if ($dynread{$builddir}) { + return 0; + } + $builddir=~s/\/[^\/]+$//; + } +# Actually get the data %dynhash= (%dynhash,&Apache::lonmeta::get_dynamic_metadata_from_sql($uri)); - &Apache::lonnet::logthis('Found: '.$uri." : ".join(',',keys %dynhash)); +# Remember that we got it + $dynread{$uri}=1; } } @@ -874,15 +895,8 @@ sub display_line { } # Set the icon for the file my $iconname = &Apache::loncommon::icon($listname); - $r->print(""); + $r->print(""); - my $metafile = $Apache::lonnet::perlvar{'lonDocRoot'}.$pathprefix. - $filecom[0].'.meta'; - if (-e $metafile) { - $metafile=1; - } else { - $metafile=0; - } if ($ENV{'form.catalogmode'} eq 'interactive') { $r->print(""); @@ -986,7 +1000,47 @@ sub display_line { $r->print(' '.($lang eq '' ? ' ' : $lang). " \n"); } + if ($hash{'display_attrs_8'} == 1) { +# statistics + &dynmetaread($filelink); + $r->print(""); + &dynmetaprint($r,$filelink,'count'); + &dynmetaprint($r,$filelink,'course'); + &dynmetaprint($r,$filelink,'stdno'); + &dynmetaprint($r,$filelink,'avetries'); + &dynmetaprint($r,$filelink,'difficulty'); + &dynmetaprint($r,$filelink,'disc'); + &dynmetaprint($r,$filelink,'clear'); + &dynmetaprint($r,$filelink,'technical'); + &dynmetaprint($r,$filelink,'correct'); + &dynmetaprint($r,$filelink,'helpful'); + &dynmetaprint($r,$filelink,'depth'); + $r->print(" \n"); + + } + if ($hash{'display_attrs_10'} == 1) { + my $source = &Apache::lonnet::metadata($filelink,'sourceavail'); + if($source eq 'open') { + my $sourcelink = &Apache::lonsource::make_link($filelink,$listname); + $r->print(''."Yes "."\n"); + } else { #A cuddled else. :P + $r->print(" \n"); + } + } + if ($hash{'display_attrs_11'} == 1) { +# links + &dynmetaread($filelink); + $r->print(''); + &dynmetaprint($r,$filelink,'goto_list'); + &dynmetaprint($r,$filelink,'comefrom_list'); + &dynmetaprint($r,$filelink,'sequsage_list'); + &dynmetaprint($r,$filelink,'dependencies'); + $r->print(''); + } if ($hash{'display_attrs_7'} == 1) { +# Show resource my $output=''; my $embstyle=&Apache::loncommon::fileembstyle($curfext); if ($embstyle eq 'ssi') { @@ -1014,40 +1068,6 @@ sub display_line { $r->print(' '.($output eq '' ? ' ':$output). " \n"); } - if ($hash{'display_attrs_8'} == 1) { -# statistics - $r->print(""); - if ($dynhash{$filelink}->{'stdno'}) { - $r->print(&mt('Number of students: '). - $dynhash{$filelink}->{'stdno'}.'
'); - } - $r->print(" \n"); - - } - if ($hash{'display_attrs_10'} == 1) { - my $source = &Apache::lonnet::metadata($filelink,'sourceavail'); - if($source eq 'open') { - my $sourcelink = &Apache::lonsource::make_link($filelink); - $r->print(''."Yes "."\n"); - } else { #A cuddled else. :P - $r->print(" \n"); - } - } - if ($hash{'display_attrs_11'} == 1) { -# links - $r->print("$filelink"); - if ($dynhash{$filelink}->{'goto_list'}) { - $r->print(&mt('Number of students: '). - $dynhash{$filelink}->{'goto_list'}.'
'); - } - if ($dynhash{$filelink}->{'comefrom_list'}) { - $r->print(&mt('Number of students: '). - $dynhash{$filelink}->{'comefrom_list'}.'
'); - } - $r->print(" \n"); - } $r->print("\n"); } @@ -1118,23 +1138,35 @@ sub display_line { $r->print(' '.($lang eq '' ? ' ' : $lang). " \n"); } - if ($hash{'display_attrs_7'} == 1) { - $r->print(' '); - } if ($hash{'display_attrs_8'} == 1) { $r->print(' '); } - if ($hash{'display_attrs_10'} == 1) { + if ($hash{'display_attrs_10'} == 1) { $r->print(' '); } if ($hash{'display_attrs_11'} == 1) { $r->print(' '); } + if ($hash{'display_attrs_7'} == 1) { + $r->print(' '); + } $r->print(''); } } +sub dynmetaprint { + my ($r,$filelink,$item)=@_; + if ($dynhash{$filelink}->{$item}) { + $r->print("\n
".$fieldnames{$item}.': '. + &Apache::lonmeta::prettyprint($item, + $dynhash{$filelink}->{$item}, + (($ENV{'form.catalogmode'} ne 'groupimport')?'preview':''), + '', + (($ENV{'form.catalogmode'} eq 'groupimport')?'document.forms.fileattr':''),1)); + } +} + # ------------------- prints the beginning of a form for directory or file link sub begin_form { my ($r,$uri) = @_;