--- loncom/interface/lonindexer.pm 2004/05/11 05:19:30 1.104 +++ loncom/interface/lonindexer.pm 2005/06/17 20:15:51 1.135 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Directory Indexer # -# $Id: lonindexer.pm,v 1.104 2004/05/11 05:19:30 albertel Exp $ +# $Id: lonindexer.pm,v 1.135 2005/06/17 20:15:51 www 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(); @@ -52,13 +52,16 @@ use Apache::Constants qw(:common); use Apache::lonmeta; use Apache::File; use Apache::lonlocal; +use Apache::lonsource(); use GDBM_File; # ---------------------------------------- variables used throughout the module my %hash; # global user-specific gdbm file 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 @@ -70,6 +73,8 @@ my @Only = (); my @Omit = (); + + # ----------------------------- Handling routine called via Apache and mod_perl sub handler { my $r = shift; @@ -85,6 +90,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') . "/"; @@ -113,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; @@ -125,36 +131,69 @@ 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') { + &Apache::loncommon::content_type($r,'text/html'); + my $extra=''; + 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.'\';'; + } + my $html=&Apache::lonxml::xmlbegin(); + $r->print(< + + + + + + +ENDSUBM + return OK; + } + # -------------------- 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 @@ -166,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 @@ -207,21 +246,13 @@ END $location .= "mode=".$mode."&"; $location .= "acts="; $catalogmodefunctions=<<"END"; -function select_data(title,url) { - changeTitle(title); +function select_data(url) { changeURL(url); self.close(); } function select_group() { window.location="$location"+document.forms.fileattr.acts.value; } -function changeTitle(val) { - if (opener.inf) { - if (opener.inf.document.forms.resinfo.elements.t) { - opener.inf.document.forms.resinfo.elements.t.value=val; - } - } -} function changeURL(val) { if (opener.inf) { if (opener.inf.document.forms.resinfo.elements.u) { @@ -235,12 +266,10 @@ END $location .= "form=$form&element=$element&mode=edit&acts="; $catalogmodefunctions=<print(< +$html The LearningOnline Network With CAPA Directory Browser + + ENDJS } @@ -713,7 +781,7 @@ sub display_line { # or absolute paths (for example, from sequences) my $absolute; my $pathprefix; - if ($line=~/^\/res\//) { + if ($line=~m|^/res/| && $startdir ne '') { $absolute=1; $pathprefix=''; } else { @@ -733,12 +801,11 @@ sub display_line { my $tabtag=''; my $i=0; - while ($i<=8) { + while ($i<=11) { $tabtag=join('',$tabtag," ") if $hash{'display_attrs_'.$i} == 1; $i++; } - my $valign = ($hash{'display_attrs_7'} == 1 ? 'top' : 'bottom'); # display uplink arrow @@ -757,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? @@ -770,24 +837,25 @@ sub display_line { if($filecom[15] ne '1') { return OK if (!&Apache::lonnet::allowed('bre',$pathprefix.$filecom[0])); } # make absolute links appear on different background - if ($absolute) { $fileclr='#aaaa88'; } + if ($absolute) { $fileclr='#ccdd99'; } # 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 "); @@ -795,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 @@ -809,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; } @@ -840,34 +910,16 @@ 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; - } - my $title; - if ($ENV{'form.catalogmode'} eq 'interactive') { - $title=$listname; - $title = &Apache::lonnet::metadata($filelink,'title') - if ($metafile == 1); - $title=$listname unless $title; - my $titleesc=HTML::Entities::encode($title,'<>&"'); - $titleesc=~s/\'/\\'/; #' (clean up this spare quote) + 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') { - $title=$listname; - $title = &Apache::lonnet::metadata($filelink,'title') - if ($metafile == 1); - $title=$listname unless $title; - my $titleesc=&HTML::Entities::encode($title,'<>&"'); + } elsif ($env{'form.catalogmode'} eq 'groupimport') { $r->print("
\n"); $r->print("print("checked"); } - $r->print(">\n"); - $r->print("\n"); - $r->print("
\n"); - $r->print(""); + $r->print(" />\n"); + $r->print(""); $hash{"pre_${fnum}_link"}=$filelink; - $hash{"pre_${fnum}_title"}=$titleesc; $fnum++; } # Form to open or close sequences @@ -913,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'); @@ -959,19 +1010,63 @@ sub display_line { $r->print(' '.($keywords eq '' ? ' ' : $keywords). " \n"); } +#' + if ($hash{'display_attrs_6'} == 1) { my $lang = &Apache::lonnet::metadata($filelink,'language'); $lang = &Apache::loncommon::languagedescription($lang); $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); + my $quotable_sourcelink = &Apache::loncommon::escape_single($sourcelink); + $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') { my $cache=$Apache::lonnet::perlvar{'lonDocRoot'}.$filelink. '.tmp'; - if ((!$ENV{'form.updatedisplay'}) && + if ((!$env{'form.updatedisplay'}) && (-e $cache)) { open(FH,$cache); $output=join("\n",); @@ -993,15 +1088,6 @@ sub display_line { $r->print(' '.($output eq '' ? ' ':$output). " \n"); } - if ($hash{'display_attrs_8'} == 1) { - my (%stat) = &Apache::lonmeta::dynamicmeta($filelink); - my $stat = (exists($stat{'course'}) ? $stat{'course'} : ''). - ((exists($stat{'course'}) || exists($stat{'count'})) ? '/' : ''). - (exists($stat{'count'}) ? $stat{'count'} : ''); - $r->print(' '.($stat eq '' ? ' ' : $stat). - ' '."\n"); - } - $r->print("\n"); } @@ -1028,12 +1114,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"); @@ -1072,17 +1160,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) { + $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) = @_; @@ -1093,9 +1199,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++; } @@ -1133,6 +1239,10 @@ sub cleanup { } } + + + + =head1 NAME Apache::lonindexer - mod_perl module for cross server filesystem browsing