--- loncom/interface/lonindexer.pm 2003/12/22 18:58:26 1.82
+++ loncom/interface/lonindexer.pm 2006/05/31 16:22:10 1.143
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Directory Indexer
#
-# $Id: lonindexer.pm,v 1.82 2003/12/22 18:58:26 www Exp $
+# $Id: lonindexer.pm,v 1.143 2006/05/31 16:22:10 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,21 +25,6 @@
#
# http://www.lon-capa.org/
#
-# YEAR=1999
-# 5/21/99, 5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
-# 11/23 Gerd Kortemeyer
-# YEAR=2000
-# 07/20-08/04 H.K. Ng
-# YEAR=2001
-# 05/9-05/19/2001 H. K. Ng
-# 05/21/2001 H. K. Ng
-# 05/23/2001 H. K. Ng
-# 6/26,7/8 H. K. Ng
-# 8/14 H. K. Ng
-# 11/30 Matthew Hall
-# YEAR=2002
-# 6/29/2002 H. K. Ng
-#
###
###############################################################################
@@ -59,19 +44,24 @@ 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();
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; # tied to a user-specific gdbm file
+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
@@ -83,19 +73,7 @@ my @Only = ();
my @Omit = ();
-# ------------------------------------------------------- Puts directory header
-sub crumbs {
- my $uri=shift;
- my $output=' /';
- my $path='/';
- foreach (split('/',$uri)) {
- unless ($_) { next; }
- $path.=$_.'/';
- $output.=''.$_.'/';
- }
- return $output.' ';
-}
# ----------------------------- Handling routine called via Apache and mod_perl
sub handler {
@@ -112,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') . "/";
@@ -137,14 +116,14 @@ sub handler {
my $closebutton='';
my $groupimportbutton='';
my $colspan='';
-
+
$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;
- if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
+ if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_READER(),0640)) {
while(my($key,$value)=each(%dbfile)) {
$hash{$key}=$value;
}
@@ -152,36 +131,67 @@ 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 $js = <
+ function load() {
+ window.opener.document.forms["$env{'form.form'}"]
+ .elements["$env{'form.element'}"]
+ .value='$env{'form.acts'}';
+ $extra
+ window.close();
+ }
+
+ENDSUBM
+ $r->print(&Apache::loncommon::start_page(undef,$js,
+ {'only_body' =>1,
+ 'add_entries' =>
+ {'onload' => "load();"},}
+ ).
+ &Apache::loncommon::end_page());
+ 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');
- 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
@@ -192,35 +202,34 @@ END
# selection is made.
# $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' );
+ #&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' );
# 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");
+ #&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
@@ -235,21 +244,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) {
@@ -263,12 +264,10 @@ END
$location .= "form=$form&element=$element&mode=edit&acts=";
$catalogmodefunctions=<print(<
-
-The LearningOnline Network With CAPA Directory Browser
-
+ my $js = <<"ENDHEADER";
-
-
ENDHEADER
-my ($headerdom)=($uri=~/^\/res\/(\w+)\//);
-$r->print(&Apache::loncommon::bodytag('Browse Resources',undef,undef,undef,
- $headerdom));
+
+ my ($headerdom)=($uri=~/^\/res\/(\w+)\//);
+ $r->print(&Apache::loncommon::start_page('Browse Resources',$js,
+ {'domain' => $headerdom,}));
# - Evaluate actions from previous page (both cumulatively and chronologically)
- if ($ENV{'form.catalogmode'} eq 'groupimport') {
- my $acts=$ENV{'form.acts'};
+ if ($env{'form.catalogmode'} eq 'groupimport') {
+ my $acts=$env{'form.acts'};
my @Acts=split(/b/,$acts);
my %ahash;
my %achash;
@@ -388,7 +382,7 @@ $r->print(&Apache::loncommon::bodytag('B
$achash{$ref}=$ac;
$ac++;
}
- # sorting through the actions and changing the tied database hash
+ # sorting through the actions and changing the global database hash
foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
my $key=$_;
if ($ahash{$key} eq '1') {
@@ -417,19 +411,20 @@ $r->print(&Apache::loncommon::bodytag('B
}
# ---------------------------------- get state of file attributes to be showing
- if ($ENV{'form.attrs'} ne '') {
- for (my $i=0; $i<=9; $i++) {
+ if ($env{'form.attrs'}) {
+ for (my $i=0; $i<=11; $i++) {
delete $hash{'display_attrs_'.$i};
- if ($ENV{'form.attr'.$i} == 1) {
+ if ($env{'form.attr'.$i} == 1) {
$attrchk[$i] = 'checked';
$hash{'display_attrs_'.$i} = 1;
}
}
} else {
- for (my $i=0; $i<=9; $i++) {
+ for (my $i=0; $i<=11; $i++) {
$attrchk[$i] = 'checked' if $hash{'display_attrs_'.$i} == 1;
}
}
+
# ------------------------------- output state of file attributes to be showing
# All versions has to the last item
# since it does not take an extra col
@@ -442,45 +437,73 @@ $r->print(&Apache::loncommon::bodytag('B
'au' => 'Author',
'kw' => 'Keywords',
'ln' => 'Language',
+ 'sa' => 'Source Available',
'sr' => 'Show resource',
+ 'li' => 'Linked/Related Resources',
'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{'au'}
-
$lt{'kw'}
-
$lt{'ln'}
-
$lt{'sr'}
-
$lt{'av'}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
-
-$closebutton
-$groupimportbutton
-
+$closebutton $groupimportbutton
END
+# -------------- Filter out sequence containment in crumbs and "recent folders"
+ my $storeuri=$uri;
+ $storeuri='/'.(split(/\.(page|sequence)\/\//,$uri))[-1];
+ $storeuri=~s/\/+/\//g;
# ---------------------------------------------------------------- Bread crumbs
- $r->print(&crumbs($uri));
+ $r->print(&Apache::lonhtmlcommon::crumbs($storeuri,'','',
+ (($env{'form.catalogmode'} eq 'groupimport')?
+ 'document.forms.fileattr':'')).
+ &Apache::lonhtmlcommon::select_recent('residx','resrecent',
+'window.status=this.form.resrecent.options[this.form.resrecent.selectedIndex].value;this.form.action=this.form.resrecent.options[this.form.resrecent.selectedIndex].value;this.form.submit();'));
+# -------------------------------------------------------- Resource Home Button
+ my $reshome=$env{'course.'.$env{'request.course.id'}.'.reshome'};
+ if ($reshome) {
+ $r->print("print('javascript:document.forms.fileattr.action="'.$reshome.'";document.forms.fileattr.submit();');
+ } else {
+ $r->print($reshome);
+ }
+ $r->print("'>".&mt('Home').'');
+ }
+ $r->print('');
+# ------------------------------------------------------ Remember where we were
+ &Apache::loncommon::storeresurl($storeuri);
+ &Apache::lonhtmlcommon::store_recent('residx',$storeuri,$storeuri);
# ----------------- output starting row to the indexed file/directory hierarchy
my $titleclr="#ddffff";
-# $r->print(&initdebug());
-# $r->print(&writedebug("Omit:@Omit")) if (@Omit);
-# $r->print(&writedebug("Only:@Only")) if (@Only);
- $r->print("
\n");
- $r->print("
\n");
+ #$r->print(&initdebug());
+ #$r->print(&writedebug("Omit:@Omit")) if (@Omit);
+ #$r->print(&writedebug("Only:@Only")) if (@Only);
+ $r->print('
'."\n");
+ $r->print('
'."\n");
$r->print("
".&mt('Name')."
\n");
$r->print("
".&mt('Title')."
\n")
if ($hash{'display_attrs_0'} == 1);
@@ -496,11 +519,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("
\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"
@@ -512,8 +539,8 @@ END
}
}
- if ($ENV{'form.openuri'}) { # take care of review and refresh options
- my $uri=$ENV{'form.openuri'};
+ if ($env{'form.openuri'}) { # take care of review and refresh options
+ my $uri=$env{'form.openuri'};
if (exists($hash{'diropen_status_'.$uri})) {
my $cursta = $hash{'diropen_status_'.$uri};
$dirs{$uri} = 'open';
@@ -528,18 +555,16 @@ END
}
}
- my $bredir = $ENV{'form.dirPointer'};
my $toplevel;
my $indent = 0;
$uri = $uri.'/' if $uri !~ /.*\/$/;
- if ($bredir ne 'on') {
- $hash{'top.level'} = $uri;
- $toplevel = $uri;
-
- } else {
- $toplevel = $hash{'top.level'};
- }
+ if ($env{'form.dirPointer'} ne 'on') {
+ $hash{'top.level'} = $uri;
+ $toplevel = $uri;
+ } else {
+ $toplevel = $hash{'top.level'};
+ }
# -------------------------------- if not at top level, provide an uplink arrow
if ($toplevel ne '/res/'){
@@ -556,20 +581,17 @@ END
# ---------------------------- embed hidden information useful for group import
$r->print("");
+ $r->print("");
# -------------------------------------------------------------- end the tables
$r->print('
');
$r->print('
');
# --------------------------------------------------- end the output and return
- $r->print('