--- loncom/interface/lonindexer.pm 2006/05/31 16:22:10 1.143
+++ loncom/interface/lonindexer.pm 2008/12/17 18:49:13 1.181.2.2
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Directory Indexer
#
-# $Id: lonindexer.pm,v 1.143 2006/05/31 16:22:10 www Exp $
+# $Id: lonindexer.pm,v 1.181.2.2 2008/12/17 18:49:13 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -53,7 +53,9 @@ use Apache::lonmeta;
use Apache::File;
use Apache::lonlocal;
use Apache::lonsource();
+use Apache::groupsort();
use GDBM_File;
+use LONCAPA qw(:match);
# ---------------------------------------- variables used throughout the module
my %hash; # global user-specific gdbm file
@@ -104,7 +106,7 @@ sub handler {
my $fileclr='#ffffe6';
my $line;
- my (@attrchk,@openpath);
+ my (@attrchk,@openpath,$typeselect);
my $uri=$r->uri;
# -------------------------------------- see if called from an interactive mode
@@ -119,21 +121,26 @@ 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'}_sel_res.db";
%hash = ();
{
my %dbfile;
- if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_READER(),0640)) {
+ if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_WRITER(),0640)) {
+ if ($env{'form.launch'} eq '1') {
+ &start_fresh_session(\%dbfile);
+ }
while(my($key,$value)=each(%dbfile)) {
$hash{$key}=$value;
}
untie(%dbfile);
}
}
- {
- if ($env{'form.launch'} eq '1') {
- &start_fresh_session();
+# - Evaluate actions from previous page (both cumulatively and chronologically)
+ if ($env{'form.catalogmode'} eq 'import' || $hash{'form.catalogmode'} eq 'import') {
+ &Apache::groupsort::update_actions_hash(\%hash);
}
+
+ {
#Hijack lonindexer to verify a title and be close down.
if ($env{'form.launch'} eq '2') {
&Apache::loncommon::content_type($r,'text/html');
@@ -171,18 +178,18 @@ ENDSUBM
# --------------------- define extra fields and buttons in case of special mode
if ($env{'form.catalogmode'} eq 'interactive') {
$extrafield='
';
+ '';
$colspan=" colspan='2' ";
my $cl=&mt('Close');
my $gi=&mt('Import');
@@ -229,7 +236,7 @@ END
# ------ set catalogmodefunctions to have extra needed javascript functionality
my $catalogmodefunctions='';
if ($env{'form.catalogmode'} eq 'interactive' or
- $env{'form.catalogmode'} eq 'groupimport') {
+ $env{'form.catalogmode'} eq 'import') {
# 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
@@ -240,7 +247,7 @@ END
#
#
if (!defined($mode) || ($mode ne 'edit' && $mode ne 'parmset')) {
- my $location = "/adm/groupsort?catalogmode=groupimport&";
+ my $location = "/adm/groupsort?&inhibitmenu=yes&catalogmode=import&";
$location .= "mode=".$mode."&";
$location .= "acts=";
$catalogmodefunctions=<<"END";
@@ -267,6 +274,9 @@ END
function select_data(url) {
var location = "/res/?launch=2&form=$form&element=$element&titleelement=$titleelement&acts=" + url;
window.location=location;
+ if (window.opener.document.forms["$form"].elements["$element"].value != url) {
+ window.opener.unClean();
+ }
}
function select_group() {
window.location="$location"+document.forms.fileattr.acts.value;
@@ -327,7 +337,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 'import') {
$catalogmodefunctions.=<
-$catalogmodefunctions
+$catalogmodefunctions;
+function update_only(field) {
+ alert(field.name);
+}
+function checkAll() {
+ var numForms = document.forms.length;
+ for (i=0;i
ENDHEADER
- my ($headerdom)=($uri=~/^\/res\/(\w+)\//);
+ my ($headerdom)=($uri=~m{^/res/($match_domain)/});
$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'};
- my @Acts=split(/b/,$acts);
- my %ahash;
- my %achash;
- my $ac=0;
- # some initial hashes for working with data
- foreach (@Acts) {
- my ($state,$ref)=split(/a/);
- $ahash{$ref}=$state;
- $achash{$ref}=$ac;
- $ac++;
- }
- # 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') {
- $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
- $hash{'pre_'.$key.'_title'};
- $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
- $hash{'storectr'}+0;
- $hash{'storectr'}++;
- }
- if ($ahash{$key} eq '0') {
- if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
- delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
- }
- }
- }
- # deleting the previously cached listing
- foreach (keys %hash) {
- if ($_ =~ /^pre_/ && $_ =~/link$/) {
- my $key = $_;
- $key =~ s/^pre_//;
- $key =~ s/_[^_]*$//;
- delete $hash{'pre_'.$key.'_title'};
- delete $hash{'pre_'.$key.'_link'};
- }
- }
+# ---------------------------------- get state of file types to be showing
+ if ($env{'form.only'}) {
+ $typeselect = $env{'form.only'};
+ } else {
+ $typeselect = '';
}
-
+
# ---------------------------------- get state of file attributes to be showing
if ($env{'form.attrs'}) {
for (my $i=0; $i<=11; $i++) {
@@ -441,7 +447,10 @@ ENDHEADER
'sr' => 'Show resource',
'li' => 'Linked/Related Resources',
'av' => 'All versions',
- 'ud' => 'Update Display'
+ 'ud' => 'Update Display',
+ 'pr' => 'Problems',
+ 'gr' => 'Graphics',
+ 'at' => 'All types'
);
$r->print(<
+END
+ my @file_categories = &Apache::loncommon::filecategories();
+ my %select_file_categories;
+ my @select_form_order = ('');
+ $select_file_categories{''} = &mt('All file types');
+ foreach my $cat (@file_categories) {
+ my $types = join(",",&Apache::loncommon::filecategorytypes($cat));
+ $select_file_categories{$types} = $cat;
+ push(@select_form_order,$types);
+ }
+ $select_file_categories{'select_form_order'} = \@select_form_order;
+ my $type_element=
+ &Apache::loncommon::select_form($typeselect,'only',
+ %select_file_categories);
+ $type_element = '';
+ $r->print(<
$closebutton $groupimportbutton
END
+ $r->print(&Apache::loncommon::inhibit_menu_check('input'));
+
# -------------- 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(&Apache::lonhtmlcommon::crumbs($storeuri,'','',
- (($env{'form.catalogmode'} eq 'groupimport')?
+ (($env{'form.catalogmode'} eq 'import')?
'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();'));
@@ -486,8 +516,8 @@ END
my $reshome=$env{'course.'.$env{'request.course.id'}.'.reshome'};
if ($reshome) {
$r->print("print('javascript:document.forms.fileattr.action="'.$reshome.'";document.forms.fileattr.submit();');
+ if ($env{'form.catalogmode'} eq 'import') {
+ $r->print('javascript:document.forms.fileattr.action="'.&Apache::loncommon::inhibit_menu_check($reshome).'";document.forms.fileattr.submit();');
} else {
$r->print($reshome);
}
@@ -497,6 +527,11 @@ END
# ------------------------------------------------------ Remember where we were
&Apache::loncommon::storeresurl($storeuri);
&Apache::lonhtmlcommon::store_recent('residx',$storeuri,$storeuri);
+# -------------------------------------------------- Check All and Uncheck all
+ if ($env{'form.catalogmode'} eq 'import') {
+ $r->print(' ');
+ $r->print('');
+ }
# ----------------- output starting row to the indexed file/directory hierarchy
my $titleclr="#ddffff";
#$r->print(&initdebug());
@@ -507,8 +542,8 @@ END
$r->print("
".&mt('Name')."
\n");
$r->print("
".&mt('Title')."
\n")
if ($hash{'display_attrs_0'} == 1);
- $r->print("
".&mt("Size")." (".&mt("bytes").") ".
- "
\n") if ($hash{'display_attrs_1'} == 1);
+ $r->print('
'.&mt('Size').' ('.&mt('bytes').') '.
+ '
'."\n") if ($hash{'display_attrs_1'} == 1);
$r->print("
".&mt("Last accessed")."
\n")
if ($hash{'display_attrs_2'} == 1);
$r->print("
".&mt("Last modified")."
\n")
@@ -579,12 +614,13 @@ END
# -------- recursively go through all the directories and output as appropriate
&scanDir ($r,$toplevel,$indent,\%hash);
-# ---------------------------- embed hidden information useful for group import
- $r->print("");
# -------------------------------------------------------------- end the tables
$r->print('');
+# ---------------------------- embed hidden information useful for group import
+ $r->print("");
+# -------------------------------------------------------------- end the tables
$r->print('');
# --------------------------------------------------- end the output and return
@@ -621,7 +657,7 @@ sub scanDir {
next if($strip =~ /.*\.meta$/ | $obs eq '1');
my (@fileparts) = split(/\./,$strip);
if ($hash{'display_attrs_9'} != 1) {
-# if not all versions to be shown
+ # if not all versions to be shown
if (scalar(@fileparts) >= 3) {
my $fext = pop @fileparts;
my $ov = pop @fileparts;
@@ -677,7 +713,7 @@ sub get_list {
$uri=~s/\/+/\//g;
foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$uri))) {
my @ratpart=split(/\:/,$_);
- push @list,$ratpart[1];
+ push(@list,&LONCAPA::map::qtescape($ratpart[1]));
}
$hash{'dirlist_files_'.$luri} = join("\n",@list);
} else {
@@ -686,7 +722,7 @@ sub get_list {
$hash{'dirlist_files_'.$luri} = join("\n",@list);
$hash{'dirlist_timestamp_files_'.$luri} = time;
}
- return @list=&match_ext($r,@list);
+ return @list=&match_ext($r,@list);
}
sub dynmetaread {
@@ -796,7 +832,8 @@ sub display_line {
my $i=0;
while ($i<=11) {
$tabtag=join('',$tabtag,"
")
- if $hash{'display_attrs_'.$i} == 1;
+ if ($i != 9 &&
+ $hash{'display_attrs_'.$i} == 1);
$i++;
}
my $valign = ($hash{'display_attrs_7'} == 1 ? 'top' : 'bottom');
@@ -808,7 +845,7 @@ sub display_line {
$updir='/'.(split(/\.(page|sequence)\/\//,$startdir))[-1];
$updir=~s/\/+/\//g;
- $r->print("
$extrafield");
+ $r->print("
$extrafield");
$r->print("
\n");
$r->print ('$tabtag
\n");
return OK;
@@ -836,24 +874,24 @@ sub display_line {
if ($filecom[1] eq 'domain') {
$r->print (''."\n")
if ($env{'form.dirPointer'} eq "on");
- $r->print("