--- loncom/interface/lonindexer.pm 2002/03/06 20:28:19 1.35 +++ loncom/interface/lonindexer.pm 2002/06/20 21:22:20 1.44 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Directory Indexer # -# $Id: lonindexer.pm,v 1.35 2002/03/06 20:28:19 matthew Exp $ +# $Id: lonindexer.pm,v 1.44 2002/06/20 21:22:20 ng 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; @@ -90,6 +95,11 @@ sub handler { $dnum=0; untie %hash; + # Deal with stupid global variables (is there a way around making + # these global to this package? It is just so wrong....) + undef (@Only); + undef (@Omit); + # ------------------------------------- read in machine configuration variables my $iconpath= $r->dir_config('lonIconsURL') . "/"; my $domain = $r->dir_config('lonDefDomain'); @@ -107,7 +117,9 @@ sub handler { # -------------------------------------- see if called from an interactive mode # Get the parameters from the query string - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['catalogmode','launch','acts','mode','form','element', + 'only','omit']); #------------------------------------------------------------------- my $closebutton=''; my $groupimportbutton=''; @@ -120,8 +132,7 @@ sub handler { if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) { if ($ENV{'form.launch'} eq '1') { &start_fresh_session(); - } - + } # -------------------- refresh environment with user database values (in %hash) if ($hash{'mode_catalog'} eq 'interactive') { $ENV{'form.catalogmode'}='interactive'; @@ -163,14 +174,24 @@ END # selection is made. # $element is the name of the element in $formname which receives # the URL. - &Apache::lonxml::debug('Checking mode, form, element'); + # &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') { + if ($mode eq 'edit' || $mode eq 'parmset') { $form = $ENV{'form.form'}; $element = $ENV{'form.element'}; } @@ -183,7 +204,15 @@ END # by default (ie. if $mode is undefined). This is the easy # 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') { + +# +# There is now also mode "simple", which is for the simple version of the rat +# +# + if (!defined($mode) || ($mode ne 'edit' && $mode ne 'parmset')) { + my $location = "/adm/groupsort?catalogmode=groupimport&"; + $location .= "mode=".$mode."&"; + $location .= "acts="; $catalogmodefunctions=<<"END"; function select_data(title,url) { changeTitle(title); @@ -191,7 +220,7 @@ function select_data(title,url) { 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) { @@ -208,7 +237,9 @@ function changeURL(val) { } } END - } else { # we are in 'edit' mode + } elsif ($mode eq 'edit') { # we are in 'edit' mode + my $location = "/adm/groupsort?catalogmode=interactive&"; + $location .= "form=$form&element=$element&mode=edit&acts="; $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 "") { @@ -362,8 +422,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); @@ -516,6 +579,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)=@_;
@@ -637,6 +723,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);
@@ -653,8 +747,8 @@ sub display_line {
 	    $title = &Apache::lonnet::metadata($filelink,'title')
 		if ($metafile == 1);
 	    $title=$listname unless $title;
-	    my $titleesc=$title;
-	    $titleesc=~s/\'/\\'/; #' (clean up this spare quote
+	    my $titleesc=HTML::Entities::encode($title);
+	    $titleesc=~s/\'/\\'/; #' (clean up this spare quote)
             $r->print("");
 	    $r->print("".
@@ -666,6 +760,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("
NameSize (bytes) ". ""); $hash{"pre_${fnum}_link"}=$filelink; - $hash{"pre_${fnum}_title"}=$title; + $hash{"pre_${fnum}_title"}=$titleesc; $fnum++; } @@ -804,6 +899,8 @@ sub start_fresh_session { 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{$_};