[LON-CAPA-cvs] cvs: loncom /interface lonindexer.pm

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 25 Mar 2002 19:27:17 -0000


matthew		Mon Mar 25 14:27:17 2002 EDT

  Modified files:              
    /loncom/interface	lonindexer.pm 
  Log:
  Added 'omit=' and 'only=' tags which cause the indexer to omit (or only 
  include) files with the given extension.
  
  
Index: loncom/interface/lonindexer.pm
diff -u loncom/interface/lonindexer.pm:1.39 loncom/interface/lonindexer.pm:1.40
--- loncom/interface/lonindexer.pm:1.39	Tue Mar 19 14:55:52 2002
+++ loncom/interface/lonindexer.pm	Mon Mar 25 14:27:17 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Directory Indexer
 #
-# $Id: lonindexer.pm,v 1.39 2002/03/19 19:55:52 matthew Exp $
+# $Id: lonindexer.pm,v 1.40 2002/03/25 19:27:17 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -80,6 +80,11 @@
 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;
@@ -108,7 +113,8 @@
 # -------------------------------------- see if called from an interactive mode
     # Get the parameters from the query string
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
-	     ['catalogmode','launch','acts','mode','form','element']);
+	     ['catalogmode','launch','acts','mode','form','element',
+              'only','omit']);
     #-------------------------------------------------------------------
     my $closebutton='';
     my $groupimportbutton='';
@@ -168,7 +174,17 @@
 	&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') {
@@ -185,6 +201,8 @@
 	    # way out.  Hopefully in the future I'll find a way to get 
 	    # the calls dealt with in a more comprehensive manner.
 	    if (!defined($mode) || ($mode ne 'edit' && $mode ne 'parmset')) {
+                my $location = "/adm/groupsort?catalogmode=groupimport&";
+                $location .= "acts=";
 		$catalogmodefunctions=<<"END";
 function select_data(title,url) {
     changeTitle(title);
@@ -192,7 +210,7 @@
     self.close();
 }
 function select_group() {
-    window.location="/adm/groupsort?catalogmode=groupimport&acts="+document.forms.fileattr.acts.value;
+    window.location="$location"+document.forms.fileattr.acts.value;
 }
 function changeTitle(val) {
     if (opener.inf) {
@@ -210,6 +228,8 @@
 }
 END
             } elsif ($mode eq 'edit') { # we are in 'edit' mode
+                my $location = "/adm/groupsort?catalogmode=interactive&";
+                $location .= "form=$form&element=$element&mode=edit&acts=";
 		$catalogmodefunctions=<<END;
 // mode = $mode
 function select_data(title,url) {
@@ -218,7 +238,7 @@
 }
 
 function select_group() {
-    window.location="/adm/groupsort?catalogmode=interactive&form=$form&element=$element&mode=edit&acts="+document.forms.fileattr.acts.value;
+    window.location="$location"+document.forms.fileattr.acts.value;
 }
 
 function changeURL(val) {
@@ -231,6 +251,8 @@
 
 END
             } elsif ($mode eq 'parmset') {
+                my $location = "/adm/groupsort?catalogmode=interactive&";
+                $location .= "form=$form&element=$element&mode=parmset&acts=";
 		$catalogmodefunctions=<<END;
 // mode = $mode
 function select_data(title,url) {
@@ -239,7 +261,7 @@
 }
 
 function select_group() {
-    window.location="/adm/groupsort?catalogmode=interactive&form=$form&element=$element&mode=parmset&acts="+document.forms.fileattr.acts.value;
+    window.location="$location"+document.forms.fileattr.acts.value;
 }
 
 function changeURL(val) {
@@ -389,8 +411,11 @@
 
 # ----------------- output starting row to the indexed file/directory hierarchy
         my $titleclr="#ddffff";
-        $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");
-	$r->print("<table border=0><tr>\n");
+#        $r->print(&initdebug());
+#        $r->print(&writedebug("Omit:@Omit")) if (@Omit);
+#        $r->print(&writedebug("Only:@Only")) if (@Only);
+        $r->print("<table width='100\%' border=0><tr><td bgcolor=#eeeeee>\n");
+	$r->print("<table width='100\%' border=0><tr>\n");
 	$r->print("<td $colspan bgcolor=$titleclr><b>Name</b></td>\n");
 	$r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) ".
 		  "</b></td>\n") if ($hash{'display_attrs_0'} == 1);
@@ -543,6 +568,29 @@
     return @list=&match_ext($r,@list);
 }
 
+sub initdebug {
+    return <<ENDJS;
+<script>
+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("<html><head><title>Debugging Window</title></head><body><pre>");   
+</script>
+ENDJS
+}
+
+sub writedebug {
+    my $text = shift;
+    return "<script>output('$text');</script>";
+}
+
 # -------------------- filters out files based on extensions (returns an array)
 sub match_ext {
     my ($r,@packlist)=@_;
@@ -664,6 +712,14 @@
     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);
@@ -831,6 +887,8 @@
     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{$_};