--- loncom/interface/lonindexer.pm 2004/06/18 01:27:04 1.116 +++ loncom/interface/lonindexer.pm 2006/02/07 19:46:30 1.138 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Directory Indexer # -# $Id: lonindexer.pm,v 1.116 2004/06/18 01:27:04 www Exp $ +# $Id: lonindexer.pm,v 1.138 2006/02/07 19:46:30 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -44,7 +44,7 @@ package Apache::lonindexer; # ------------------------------------------------- modules used by this module use strict; -use Apache::lonnet(); +use Apache::lonnet; use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::lonsequence(); @@ -60,6 +60,7 @@ 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. @@ -72,6 +73,8 @@ my @Only = (); my @Omit = (); + + # ----------------------------- Handling routine called via Apache and mod_perl sub handler { my $r = shift; @@ -116,7 +119,7 @@ sub handler { $extrafield=''; my $diropendb = - "/home/httpd/perl/tmp/$ENV{'user.domain'}_$ENV{'user.name'}_indexer.db"; + "/home/httpd/perl/tmp/$env{'user.domain'}_$env{'user.name'}_indexer.db"; %hash = (); { my %dbfile; @@ -128,29 +131,36 @@ sub handler { } } { - if ($ENV{'form.launch'} eq '1') { + if ($env{'form.launch'} eq '1') { &start_fresh_session(); } #Hijack lonindexer to verify a title and be close down. - if ($ENV{'form.launch'} eq '2') { - $r->content_type('text/html'); + if ($env{'form.launch'} eq '2') { + &Apache::loncommon::content_type($r,'text/html'); my $extra=''; - if (defined($ENV{'form.titleelement'})) { - my $verify_title = &Apache::lonnet::gettitle($ENV{'form.acts'}); -# &Apache::lonnet::logthis("Hrrm $ENV{'form.acts'} -- $verify_title"); + 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"); $verify_title=~s/'/\\'/g; - $extra='window.opener.document.forms["'.$ENV{'form.form'}.'"].elements["'.$ENV{'form.titleelement'}.'"].value=\''.$verify_title.'\';'; + $extra='window.opener.document.forms["'.$env{'form.form'}.'"].elements["'.$env{'form.titleelement'}.'"].value=\''.$verify_title.'\';'; } + my $html=&Apache::lonxml::xmlbegin(); $r->print(< - - + + + ENDSUBM @@ -158,32 +168,32 @@ ENDSUBM } # -------------------- refresh environment with user database values (in %hash) - &setvalues(\%hash,'form.catalogmode',\%ENV,'form.catalogmode' ); + &setvalues(\%hash,'form.catalogmode',\%env,'form.catalogmode' ); # --------------------- define extra fields and buttons in case of special mode - if ($ENV{'form.catalogmode'} eq 'interactive') { + if ($env{'form.catalogmode'} eq 'interactive') { $extrafield=''. ''; $colspan=" colspan='2' "; my $cl=&mt('Close'); $closebutton=< + END } - elsif ($ENV{'form.catalogmode'} eq 'groupimport') { + elsif ($env{'form.catalogmode'} eq 'groupimport') { $extrafield=''. ''; $colspan=" colspan='2' "; my $cl=&mt('Close'); - my $gi=&mt('Group Import'); + my $gi=&mt('Import'); $closebutton=< + END $groupimportbutton=< +onClick="javascript:select_group()" /> END } # Additions made by Matthew to make the browser a little easier to deal @@ -195,33 +205,33 @@ END # $element is the name of the element in $formname which receives # the URL. #&Apache::lonxml::debug('Checking mode, form, element'); - &setvalues(\%hash,'form.mode' ,\%ENV,'form.mode' ); - &setvalues(\%hash,'form.form' ,\%ENV,'form.form' ); - &setvalues(\%hash,'form.element' ,\%ENV,'form.element'); - &setvalues(\%hash,'form.titleelement',\%ENV,'form.titleelement'); - &setvalues(\%hash,'form.only' ,\%ENV,'form.only' ); - &setvalues(\%hash,'form.omit' ,\%ENV,'form.omit' ); + &setvalues(\%hash,'form.mode' ,\%env,'form.mode' ); + &setvalues(\%hash,'form.form' ,\%env,'form.form' ); + &setvalues(\%hash,'form.element' ,\%env,'form.element'); + &setvalues(\%hash,'form.titleelement',\%env,'form.titleelement'); + &setvalues(\%hash,'form.only' ,\%env,'form.only' ); + &setvalues(\%hash,'form.omit' ,\%env,'form.omit' ); # Deal with 'omit' and 'only' - if (exists $ENV{'form.omit'}) { - @Omit = split(',',$ENV{'form.omit'}); + if (exists $env{'form.omit'}) { + @Omit = split(',',$env{'form.omit'}); } - if (exists $ENV{'form.only'}) { - @Only = split(',',$ENV{'form.only'}); + if (exists $env{'form.only'}) { + @Only = split(',',$env{'form.only'}); } - my $mode = $ENV{'form.mode'}; + my $mode = $env{'form.mode'}; my ($form,$element,$titleelement); if ($mode eq 'edit' || $mode eq 'parmset') { - $form = $ENV{'form.form'}; - $element = $ENV{'form.element'}; - $titleelement = $ENV{'form.titleelement'}; + $form = $env{'form.form'}; + $element = $env{'form.element'}; + $titleelement = $env{'form.titleelement'}; } #&Apache::lonxml::debug("mode=$mode form=$form element=$element titleelement=$titleelement"); # ------ set catalogmodefunctions to have extra needed javascript functionality my $catalogmodefunctions=''; - if ($ENV{'form.catalogmode'} eq 'interactive' or - $ENV{'form.catalogmode'} eq 'groupimport') { + if ($env{'form.catalogmode'} eq 'interactive' or + $env{'form.catalogmode'} eq 'groupimport') { # The if statement below sets us up to use the old version # by default (ie. if $mode is undefined). This is the easy # way out. Hopefully in the future I'll find a way to get @@ -319,7 +329,7 @@ function rep_dirpath(suffix,val) { eval("document.forms.dirpath"+suffix+".acts.value=val"); } END - if ($ENV{'form.catalogmode'} eq 'groupimport') { + if ($env{'form.catalogmode'} eq 'groupimport') { $catalogmodefunctions.=<print(< +$html The LearningOnline Network With CAPA Directory Browser + + ENDJS } @@ -795,12 +824,12 @@ sub display_line { 'enctype="application/x-www-form-urlencoded"'. '>'."\n"); $r->print (''."\n"); - $r->print (''."\n"); + $startdir.'" />'."\n"); + $r->print (''."\n"); $r->print ('print (' name="'.$msg.'" height="22" type="image" border="0">'. + $r->print (' name="'.$msg.'" height="22" type="image" border="0" />'. "\n"); - $r->print(&mt("Up")." $tabtag\n"); + $r->print(&mt("Up")."$tabtag\n"); return OK; } # Do we have permission to look at this? @@ -812,20 +841,21 @@ sub display_line { # display domain if ($filecom[1] eq 'domain') { - $r->print (''."\n") - if ($ENV{'form.dirPointer'} eq "on"); + $r->print (''."\n") + if ($env{'form.dirPointer'} eq "on"); $r->print("$extrafield"); $r->print(""); &begin_form ($r,$filecom[0]); my $anchor = $filecom[0]; $anchor =~ s/\///g; $r->print (''); - $r->print (''); + $r->print (''); $r->print ('print (' name="'.$msg.'" height="22" type="image" border="0">'. + $r->print (' name="'.$msg.'" height="22" type="image" border="0" />'. "\n"); - $r->print ('print (' border="0" />'."\n"); $r->print (&mt("Domain")." - $listname "); @@ -833,7 +863,7 @@ sub display_line { $r->print("(".$Apache::lonnet::domaindescription{$listname}. ")"); } - $r->print (" $tabtag\n"); + $r->print ("$tabtag\n"); return OK; # display user directory @@ -847,19 +877,21 @@ sub display_line { &begin_form ($r,$curdir); $r->print (''."\n"); - $r->print (''); + $r->print (''); $r->print ('print (' name="'.$msg.'" height="22" type="image" border="0">'. + $r->print (' name="'.$msg.'" height="22" type="image" border="0" />'. "\n"); - $r->print (''); my $domain=(split(m|/|,$startdir))[2]; my $plainname=&Apache::loncommon::plainname($listname,$domain); $r->print ($listname); if (defined($plainname) && $plainname) { $r->print(" ($plainname) "); } - $r->print ($tabtag.''."\n"); + $r->print (''.$tabtag.''."\n"); return OK; } @@ -878,15 +910,16 @@ sub display_line { } # Set the icon for the file my $iconname = &Apache::loncommon::icon($listname); - $r->print(""); + $r->print(""); - if ($ENV{'form.catalogmode'} eq 'interactive') { + if ($env{'form.catalogmode'} eq 'interactive') { + my $quotable_filelink = &Apache::loncommon::escape_single($filelink); $r->print(""); + $quotable_filelink,"')\">"); $r->print("". "\n"); $r->print(""); - } elsif ($ENV{'form.catalogmode'} eq 'groupimport') { + } elsif ($env{'form.catalogmode'} eq 'groupimport') { $r->print("
\n"); $r->print("print("checked"); } - $r->print(">\n"); - $r->print("
\n"); - $r->print(""); + $r->print(" />\n"); + $r->print(""); $hash{"pre_${fnum}_link"}=$filelink; $fnum++; } @@ -929,25 +961,28 @@ sub display_line { my $curdir = $startdir.$filecom[0].'/'; my $anchor = $curdir; $anchor =~ s/\///g; - $r->print (''); + $r->print (''); $r->print ('print (' name="'.$msg.'" height="22" type="image" border="0">'. + $r->print (' name="'.$msg.'" height="22" type="image" border="0" />'. "\n"); } # Filetype icons $r->print("\n"); -# Close form to open/close sequence - if ($filelink=~/\.(page|sequence)$/) { - $r->print(''); - } - $r->print (" print (" $listname "); - $r->print (" (print (" (metadata) "); +# Close form to open/close sequence + if ($filelink=~/\.(page|sequence)$/) { + $r->print(''); + } $r->print("\n"); if ($hash{'display_attrs_0'} == 1) { my $title = &Apache::lonnet::gettitle($filelink,'title'); @@ -985,6 +1020,7 @@ sub display_line { } if ($hash{'display_attrs_8'} == 1) { # statistics + &dynmetaread($filelink); $r->print(""); &dynmetaprint($r,$filelink,'count'); &dynmetaprint($r,$filelink,'course'); @@ -1003,8 +1039,10 @@ sub display_line { 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(''."print(''."Yes "."\n"); } else { #A cuddled else. :P @@ -1013,6 +1051,7 @@ sub display_line { } if ($hash{'display_attrs_11'} == 1) { # links + &dynmetaread($filelink); $r->print(''); &dynmetaprint($r,$filelink,'goto_list'); &dynmetaprint($r,$filelink,'comefrom_list'); @@ -1027,16 +1066,20 @@ sub display_line { if ($embstyle eq 'ssi') { my $cache=$Apache::lonnet::perlvar{'lonDocRoot'}.$filelink. '.tmp'; - if ((!$ENV{'form.updatedisplay'}) && + if ((!$env{'form.updatedisplay'}) && (-e $cache)) { open(FH,$cache); $output=join("\n",); close(FH); } else { $output=&Apache::lonnet::ssi_body($filelink); - open(FH,">$cache"); - print FH $output; - close(FH); + if ($output=~/LONCAPAACCESSCONTROLERRORSCREEN/) { + $output=''; + } else { + open(FH,">$cache"); + print FH $output; + close(FH); + } } $output=''.$output.''; } elsif ($embstyle eq 'img') { @@ -1075,12 +1118,14 @@ sub display_line { $r->print ("\n") if $rem > 0; } - $r->print (''); + $r->print (''); $r->print ('print (' name="'.$msg.'" height="22" type="image" border="0">'. + $r->print (' name="'.$msg.'" height="22" type="image" border="0" />'. "\n"); - $r->print (''. "\n"); $r->print ("$listname\n"); @@ -1142,9 +1187,9 @@ sub dynmetaprint { $r->print("\n
".$fieldnames{$item}.': '. &Apache::lonmeta::prettyprint($item, $dynhash{$filelink}->{$item}, - (($ENV{'form.catalogmode'} ne 'groupimport')?'preview':''), + (($env{'form.catalogmode'} ne 'groupimport')?'preview':''), '', - (($ENV{'form.catalogmode'} eq 'groupimport')?'document.forms.fileattr':''),1)); + (($env{'form.catalogmode'} eq 'groupimport')?'document.forms.fileattr':''),1)); } } @@ -1158,9 +1203,9 @@ sub begin_form { '" onSubmit="return rep_dirpath(\''.$dnum.'\''. ',document.forms.fileattr.acts.value)" '. 'enctype="application/x-www-form-urlencoded">'."\n"); - $r->print (''. + $r->print (''. "\n"); - $r->print (''."\n"); + $r->print (''."\n"); $dnum++; } @@ -1196,8 +1241,13 @@ sub cleanup { if (tied(%hash)){ &Apache::lonnet::logthis('Cleanup indexer: hash'); } + return OK; } + + + + =head1 NAME Apache::lonindexer - mod_perl module for cross server filesystem browsing