--- loncom/interface/lonindexer.pm 2002/01/17 13:53:45 1.32 +++ loncom/interface/lonindexer.pm 2002/05/31 21:50:30 1.42 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Directory Indexer # -# $Id: lonindexer.pm,v 1.32 2002/01/17 13:53:45 harris41 Exp $ +# $Id: lonindexer.pm,v 1.42 2002/05/31 21:50:30 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -80,6 +80,11 @@ my $extrafield; # default extra table ce my $fnum; # file counter my $dnum; # directory counter +# ----- Used to include or exclude files with certain extensions. +my @Only = (); +my @Omit = (); + + # ----------------------------- Handling routine called via Apache and mod_perl sub handler { my $r = shift; @@ -106,8 +111,11 @@ sub handler { my $uri=$r->uri; # -------------------------------------- see if called from an interactive mode - &get_unprocessed_cgi(); - + # Get the parameters from the query string + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['catalogmode','launch','acts','mode','form','element', + 'only','omit']); + #------------------------------------------------------------------- my $closebutton=''; my $groupimportbutton=''; my $colspan=''; @@ -154,35 +162,136 @@ END onClick="javascript:select_group()"> END } - + # Additions made by Matthew to make the browser a little easier to deal + # with in the future. + # + # $mode (at this time) indicates if we are in edit mode. + # $form is the name of the form that the URL is placed when the + # 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_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.only'}) { + @Only = split(',',$ENV{'form.only'}); + } + + my $mode = $ENV{'form.mode'}; + my ($form,$element); + if ($mode eq 'edit' || $mode eq 'parmset') { + $form = $ENV{'form.form'}; + $element = $ENV{'form.element'}; + } + &Apache::lonxml::debug("mode=$mode form=$form element=$element"); # ------ set catalogmodefunctions to have extra needed javascript functionality my $catalogmodefunctions=''; if ($ENV{'form.catalogmode'} eq 'interactive' or $ENV{'form.catalogmode'} eq 'groupimport') { - $catalogmodefunctions=<print('

The LearningOnline With CAPA '. + $r->print( +'

The LearningOnline Network with CAPA '. 'Network Directory Browser

'."\n"); # ---------------------------------- get state of file attributes to be showing if ($ENV{'form.attrs'} ne "") { @@ -311,8 +418,11 @@ END # ----------------- output starting row to the indexed file/directory hierarchy my $titleclr="#ddffff"; - $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("\n"); $r->print("\n") if ($hash{'display_attrs_0'} == 1); @@ -465,6 +575,29 @@ sub get_list { return @list=&match_ext($r,@list); } +sub initdebug { + return < +var debugging = true; +if (debugging) { + var debuggingWindow = window.open('','Debug','width=400,height=300',true); +} + +function output(text) { + if (debugging) { + debuggingWindow.document.writeln(text); + } +} +output("Debugging Window
");   
+
+ENDJS
+}
+
+sub writedebug {
+    my $text = shift;
+    return "";
+}
+
 # -------------------- filters out files based on extensions (returns an array)
 sub match_ext {
     my ($r,@packlist)=@_;
@@ -586,6 +719,14 @@ sub display_line {
     if ($fnptr == 0 and $filecom[3] ne "") {
 	my @file_ext = split (/\./,$listname);
 	my $curfext = $file_ext[-1];
+        if (@Omit) {
+            foreach (@Omit) { return OK if ($curfext eq $_); }
+        }
+        if (@Only) {
+            my $skip = 1;
+            foreach (@Only) { $skip = 0 if ($curfext eq $_); }
+            return OK if ($skip > 0);
+        }
 	# Set the icon for the file
 	my $iconname = "unknown.gif";
 	my $embstyle = &Apache::loncommon::fileembstyle($curfext);
@@ -602,8 +743,10 @@ sub display_line {
 	    $title = &Apache::lonnet::metadata($filelink,'title')
 		if ($metafile == 1);
 	    $title=$listname unless $title;
-	    $r->print("");
+	    my $titleesc=HTML::Entities::encode($title);
+	    $titleesc=~s/\'/\\'/; #' (clean up this spare quote)
+            $r->print("");
 	    $r->print("".
 		      "\n");
 	    $r->print("
NameSize (bytes) ". ""); @@ -613,6 +756,7 @@ sub display_line { $title = &Apache::lonnet::metadata($filelink,'title') if ($metafile == 1); $title=$listname unless $title; + my $titleesc=&HTML::Entities::encode($title); $r->print("
\n"); $r->print("\n"); + "value='$titleesc'>\n"); $r->print("
\n"); $r->print("
"); $hash{"pre_${fnum}_link"}=$filelink; - $hash{"pre_${fnum}_title"}=$title; + $hash{"pre_${fnum}_title"}=$titleesc; $fnum++; } @@ -745,21 +889,14 @@ sub begin_form { $dnum++; } -# ----------- grab unprocessed CGI variables that may have been appended to URL -sub get_unprocessed_cgi { - foreach (split(/&/,$ENV{'QUERY_STRING'})) { - my ($name, $value) = split(/=/,$_); - $value =~ tr/+/ /; - $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; - if ($name eq 'catalogmode' or $name eq 'launch' or $name eq 'acts') { - $ENV{'form.'.$name}=$value; - } - } -} - # --------- settings whenever the user causes the indexer window to be launched sub start_fresh_session { delete $hash{'mode_catalog'}; + delete $hash{'form_mode'}; + delete $hash{'form_form'}; + delete $hash{'form_element'}; + delete $hash{'form_omit'}; + delete $hash{'form_only'}; foreach (keys %hash) { if ($_ =~ /^pre_/) { delete $hash{$_}; @@ -770,6 +907,19 @@ sub start_fresh_session { } } +# ------------------------------------------------------------------- setvalues +sub setvalues { + # setvalues is used in registerurl to synchronize the database + # hash and environment hashes + my ($H1,$h1key,$H2,$h2key) =@_; + # + if (exists $H2->{$h2key}) { + $H1->{$h1key} = $H2->{$h2key}; + } elsif (exists $H1->{$h1key}) { + $H2->{$h2key} = $H1->{$h1key}; + } +} + 1; =head1 NAME @@ -906,11 +1056,6 @@ begin_form - prints the beginning of a f =item * -get_unprocessed_cgi - grab unprocessed CGI variables that may have been -appended to URL - -=item * - start_fresh_session - settings whenever the user causes the indexer window to be launched