--- loncom/interface/lonindexer.pm 2006/06/23 07:32:02 1.148
+++ loncom/interface/lonindexer.pm 2010/04/14 16:11:34 1.181.4.6
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Directory Indexer
#
-# $Id: lonindexer.pm,v 1.148 2006/06/23 07:32:02 www Exp $
+# $Id: lonindexer.pm,v 1.181.4.6 2010/04/14 16:11:34 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
@@ -123,17 +125,22 @@ sub handler {
%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,27 +178,27 @@ 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');
$closebutton=<
+
END
}
elsif ($env{'form.catalogmode'} eq 'import') {
$extrafield='
'.
- '
';
+ '';
$colspan=" colspan='2' ";
my $cl=&mt('Close');
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
@@ -240,7 +247,7 @@ END
#
#
if (!defined($mode) || ($mode ne 'edit' && $mode ne 'parmset')) {
- my $location = "/adm/groupsort?catalogmode=import&";
+ 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;
@@ -309,10 +319,8 @@ function select_group() {
function changeURL(val) {
if (window.opener.document) {
- var elementname = "$element"+"_value";
- var checkboxname = "$element"+"_setparmval";
+ var elementname = "$element";
window.opener.document.forms["$form"].elements[elementname].value=val;
- window.opener.document.forms["$form"].elements[checkboxname].checked=true;
} else {
alert("The file you selected is: "+val);
}
@@ -344,10 +352,41 @@ function queue(val) {
END
}
+ my $inhibit_menu = "+'&".&Apache::loncommon::inhibit_menu_check()."'";
# ---------------------------------------------------------------- Print Header
+
my $js = <<"ENDHEADER";
ENDHEADER
- 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 'import') {
- 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'};
- }
- }
+ my ($headerdom)=($uri=~m{^/res/($match_domain)/});
+ my %args = (
+ 'domain' => $headerdom,
+ );
+ if ($env{'form.catalogmode'}) {
+ # "Popup mode"
+ $args{'only_body'} = 1;
+ }
+ $r->print(&Apache::loncommon::start_page('Browse Resources',$js,\%args));
+# ---------------------------------- 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++) {
+ for (my $i=0; $i<=16; $i++) {
delete $hash{'display_attrs_'.$i};
if ($env{'form.attr'.$i} == 1) {
- $attrchk[$i] = 'checked';
+ $attrchk[$i] = 'checked="checked"';
$hash{'display_attrs_'.$i} = 1;
}
}
} else {
- for (my $i=0; $i<=11; $i++) {
- $attrchk[$i] = 'checked' if $hash{'display_attrs_'.$i} == 1;
+ for (my $i=0; $i<=16; $i++) {
+ $attrchk[$i] = 'checked="checked"' if $hash{'display_attrs_'.$i} == 1;
}
}
+ 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} = &mt($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);
+ my $type_selector = '';
+
# ------------------------------- output state of file attributes to be showing
# All versions has to the last item
# since it does not take an extra col
- my %lt=&Apache::lonlocal::texthash(
- 'ti' => 'Title',
- 'si' => 'Size',
- 'la' => 'Last access',
- 'lm' => 'Last modified',
- 'st' => 'Statistics',
- 'au' => 'Author',
- 'kw' => 'Keywords',
- 'ln' => 'Language',
- 'sa' => 'Source Available',
- 'sr' => 'Show resource',
- 'li' => 'Linked/Related Resources',
- 'av' => 'All versions',
- 'ud' => 'Update Display'
- );
- $r->print(<
-
-
');
+# ---------------------------- embed hidden information useful for group import
+ $r->print("");
+# -------------------------------------------------------------- end the tables
$r->print('');
# --------------------------------------------------- end the output and return
@@ -621,7 +691,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 +747,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 +756,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 {
@@ -794,9 +864,10 @@ sub display_line {
my $tabtag='';
my $i=0;
- while ($i<=11) {
+ while ($i<=16) {
$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,26 +879,27 @@ 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;
}
# Do we have permission to look at this?
- if($filecom[15] ne '1') { return OK if (!&Apache::lonnet::allowed('bre',$pathprefix.$filecom[0])); }
+ if($filecom[15] ne '1') { return OK if ((!&Apache::lonnet::allowed('bre',$pathprefix.$filecom[0])) && (!&Apache::lonnet::allowed('bro',$pathprefix.$filecom[0]))); }
# make absolute links appear on different background
if ($absolute) { $fileclr='#ccdd99'; }
@@ -836,24 +908,24 @@ sub display_line {
if ($filecom[1] eq 'domain') {
$r->print (''."\n")
if ($env{'form.dirPointer'} eq "on");
- $r->print("