File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.90: download - view: text, annotated - select for diffs
Thu Feb 5 03:42:52 2004 UTC (20 years, 4 months ago) by taceyjo1
Branches: MAIN
CVS tags: HEAD
The bits and pieces to make it use the lond is obsolete process, should be a little faster as it does not depend on ANY meta data so long as you don't have any of the checkboxes checked.  I think, but I don't know how to profile if it's making a call to lonnet or not

    1: # The LearningOnline Network with CAPA
    2: # Directory Indexer
    3: #
    4: # $Id: lonindexer.pm,v 1.90 2004/02/05 03:42:52 taceyjo1 Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: ###############################################################################
   31: ##                                                                           ##
   32: ## ORGANIZATION OF THIS PERL MODULE                                          ##
   33: ##                                                                           ##
   34: ## 1. Description of functions                                               ##
   35: ## 2. Modules used by this module                                            ##
   36: ## 3. Choices for different output views (detailed, summary, xml, etc)       ##
   37: ## 4. BEGIN block (to be run once after compilation)                         ##
   38: ## 5. Handling routine called via Apache and mod_perl                        ##
   39: ## 6. Other subroutines                                                      ##
   40: ##                                                                           ##
   41: ###############################################################################
   42: 
   43: package Apache::lonindexer;
   44: 
   45: # ------------------------------------------------- modules used by this module
   46: use strict;
   47: use Apache::lonnet();
   48: use Apache::loncommon();
   49: use Apache::lonhtmlcommon();
   50: use Apache::Constants qw(:common);
   51: use Apache::lonmeta;
   52: use Apache::File;
   53: use Apache::lonlocal;
   54: use GDBM_File;
   55: 
   56: # ---------------------------------------- variables used throughout the module
   57: my %hash; # global user-specific gdbm file
   58: my %dirs; # keys are directories, values are the open/close status
   59: my %language; # has the reference information present in language.tab
   60: 
   61: # ----- Values which are set by the handler subroutine and are accessible to
   62: # -----     other methods.
   63: my $extrafield; # default extra table cell
   64: my $fnum; # file counter
   65: my $dnum; # directory counter
   66: 
   67: # ----- Used to include or exclude files with certain extensions.
   68: my @Only = ();
   69: my @Omit = ();
   70: 
   71: 
   72: # ----------------------------- Handling routine called via Apache and mod_perl
   73: sub handler {
   74:     my $r = shift;
   75:     my $c = $r->connection();
   76:     &Apache::loncommon::content_type($r,'text/html');
   77:     &Apache::loncommon::no_cache($r);
   78:     $r->send_http_header;
   79:     return OK if $r->header_only;
   80:     $fnum=0;
   81:     $dnum=0;
   82: 
   83:     # Deal with stupid global variables (is there a way around making
   84:     # these global to this package?  It is just so wrong....)
   85:     undef (@Only);
   86:     undef (@Omit);
   87: 
   88: # ------------------------------------- read in machine configuration variables
   89:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
   90:     my $domain  = $r->dir_config('lonDefDomain');
   91:     my $role    = $r->dir_config('lonRole');
   92:     my $loadlim = $r->dir_config('lonLoadLim');
   93:     my $servadm = $r->dir_config('lonAdmEMail');
   94:     my $sysadm  = $r->dir_config('lonSysEMail');
   95:     my $lonhost = $r->dir_config('lonHostID');
   96:     my $tabdir  = $r->dir_config('lonTabDir');
   97: 
   98:     my $fileclr='#ffffe6';
   99:     my $line;
  100:     my (@attrchk,@openpath);
  101:     my $uri=$r->uri;
  102: 
  103: # -------------------------------------- see if called from an interactive mode
  104:     # Get the parameters from the query string
  105:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  106: 	     ['catalogmode','launch','acts','mode','form','element',
  107:               'only','omit','titleelement']);
  108:     #-------------------------------------------------------------------
  109:     my $closebutton='';
  110:     my $groupimportbutton='';
  111:     my $colspan=''; 
  112: 
  113:     $extrafield='';
  114:     my $diropendb = 
  115: 	"/home/httpd/perl/tmp/$ENV{'user.domain'}_$ENV{'user.name'}_indexer.db";
  116:     %hash = ();
  117:     {
  118: 	my %dbfile;
  119: 	if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_READER(),0640)) {
  120: 	    while(my($key,$value)=each(%dbfile)) {
  121: 		$hash{$key}=$value;
  122: 	    }
  123: 	    untie(%dbfile);
  124: 	}
  125:     }
  126:     {
  127: 	if ($ENV{'form.launch'} eq '1') {
  128: 	    &start_fresh_session();
  129:         }
  130: # -------------------- refresh environment with user database values (in %hash)
  131: 	&setvalues(\%hash,'form.catalogmode',\%ENV,'form.catalogmode'   );
  132: 
  133: # --------------------- define extra fields and buttons in case of special mode
  134: 	if ($ENV{'form.catalogmode'} eq 'interactive') {
  135: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
  136: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
  137: 		' border="0" /></td>';
  138: 	    $colspan=" colspan='2' ";
  139:             my $cl=&mt('Close');
  140:             $closebutton=<<END;
  141: <input type="button" name="close" value='$cl' onClick="self.close()">
  142: END
  143:         }
  144: 	elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
  145: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
  146: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
  147: 		' border="0" /></td>';
  148: 	    $colspan=" colspan='2' ";
  149: 	    my $cl=&mt('Close');
  150:             my $gi=&mt('Group Import');
  151:             $closebutton=<<END;
  152: <input type="button" name="close" value='$cl' onClick="self.close()">
  153: END
  154:             $groupimportbutton=<<END;
  155: <input type="button" name="groupimport" value='$gi'
  156: onClick="javascript:select_group()">
  157: END
  158:         }
  159: 	# Additions made by Matthew to make the browser a little easier to deal
  160: 	# with in the future.
  161: 	#
  162: 	# $mode (at this time) indicates if we are in edit mode.
  163: 	# $form is the name of the form that the URL is placed when the
  164: 	#       selection is made.
  165: 	# $element is the name of the element in $formname which receives
  166: 	#       the URL.
  167: 	&Apache::lonxml::debug('Checking mode, form, element');
  168: 	&setvalues(\%hash,'form.mode'        ,\%ENV,'form.mode'   );
  169: 	&setvalues(\%hash,'form.form'        ,\%ENV,'form.form'   );
  170: 	&setvalues(\%hash,'form.element'     ,\%ENV,'form.element');
  171: 	&setvalues(\%hash,'form.titleelement',\%ENV,'form.titleelement');
  172: 	&setvalues(\%hash,'form.only'        ,\%ENV,'form.only'   );
  173: 	&setvalues(\%hash,'form.omit'        ,\%ENV,'form.omit'   );
  174: 
  175:         # Deal with 'omit' and 'only' 
  176:         if (exists $ENV{'form.omit'}) {
  177:             @Omit = split(',',$ENV{'form.omit'});
  178:         }
  179:         if (exists $ENV{'form.only'}) {
  180:             @Only = split(',',$ENV{'form.only'});
  181:         }
  182:         
  183: 	my $mode = $ENV{'form.mode'};
  184: 	my ($form,$element,$titleelement);
  185: 	if ($mode eq 'edit' || $mode eq 'parmset') {
  186: 	    $form         = $ENV{'form.form'};
  187: 	    $element      = $ENV{'form.element'};
  188: 	    $titleelement = $ENV{'form.titleelement'};
  189: 	}
  190: 	#&Apache::lonxml::debug("mode=$mode form=$form element=$element titleelement=$titleelement");
  191: # ------ set catalogmodefunctions to have extra needed javascript functionality
  192: 	my $catalogmodefunctions='';
  193: 	if ($ENV{'form.catalogmode'} eq 'interactive' or
  194: 	    $ENV{'form.catalogmode'} eq 'groupimport') {
  195: 	    # The if statement below sets us up to use the old version
  196: 	    # by default (ie. if $mode is undefined).  This is the easy
  197: 	    # way out.  Hopefully in the future I'll find a way to get 
  198: 	    # the calls dealt with in a more comprehensive manner.
  199: 
  200: #
  201: # There is now also mode "simple", which is for the simple version of the rat
  202: #
  203: #
  204: 	    if (!defined($mode) || ($mode ne 'edit' && $mode ne 'parmset')) {
  205:                 my $location = "/adm/groupsort?catalogmode=groupimport&";
  206:                 $location .= "mode=".$mode."&";
  207:                 $location .= "acts=";
  208: 		$catalogmodefunctions=<<"END";
  209: function select_data(title,url) {
  210:     changeTitle(title);
  211:     changeURL(url);
  212:     self.close();
  213: }
  214: function select_group() {
  215:     window.location="$location"+document.forms.fileattr.acts.value;
  216: }
  217: function changeTitle(val) {
  218:     if (opener.inf) {
  219:         if (opener.inf.document.forms.resinfo.elements.t) {
  220:             opener.inf.document.forms.resinfo.elements.t.value=val;
  221:         }
  222:     }
  223: }
  224: function changeURL(val) {
  225:     if (opener.inf) {
  226:         if (opener.inf.document.forms.resinfo.elements.u) {
  227: 	    opener.inf.document.forms.resinfo.elements.u.value=val;
  228:         }
  229:     }
  230: }
  231: END
  232:             } elsif ($mode eq 'edit') { # we are in 'edit' mode
  233:                 my $location = "/adm/groupsort?catalogmode=interactive&";
  234:                 $location .= "form=$form&element=$element&mode=edit&acts=";
  235: 		$catalogmodefunctions=<<END;
  236: // mode = $mode
  237: function select_data(title,url) {
  238:     changeURL(url);
  239:     changeTitle(title);
  240:     self.close();
  241: }
  242: 
  243: function select_group() {
  244:     window.location="$location"+document.forms.fileattr.acts.value;
  245: }
  246: 
  247: function changeURL(val) {
  248:     if (window.opener.document) {
  249: 	window.opener.document.forms["$form"].elements["$element"].value=val;
  250:     } else {
  251: 	    alert("The file you selected is: "+val);
  252:     }
  253: }
  254: END
  255:                 if (!$titleelement) {
  256: 		    $catalogmodefunctions.='function changeTitle(val) {}';
  257: 		} else {
  258: 		    $catalogmodefunctions.=<<END;
  259: function changeTitle(val) {
  260:     if (window.opener.document) {
  261: 	    window.opener.document.forms["$form"].elements["$titleelement"].value=val;
  262:     } else {
  263: 	    alert("The title of the file you selected is: "+val);
  264:     }
  265: }
  266: END
  267:                 }
  268:             } elsif ($mode eq 'parmset') {
  269:                 my $location = "/adm/groupsort?catalogmode=interactive&";
  270:                 $location .= "form=$form&element=$element&mode=parmset&acts=";
  271: 		$catalogmodefunctions=<<END;
  272: // mode = $mode
  273: function select_data(title,url) {
  274:     changeURL(url);
  275:     self.close();
  276: }
  277: 
  278: function select_group() {
  279:     window.location="$location"+document.forms.fileattr.acts.value;
  280: }
  281: 
  282: function changeURL(val) {
  283:     if (window.opener.document) {
  284:         var elementname  = "$element"+"_value";
  285:         var checkboxname = "$element"+"_setparmval";
  286: 	window.opener.document.forms["$form"].elements[elementname].value=val;
  287:         window.opener.document.forms["$form"].elements[checkboxname].checked=true;
  288:     } else {
  289: 	    alert("The file you selected is: "+val);
  290:     }
  291: }
  292: 
  293: END
  294:             }
  295:         }
  296:         $catalogmodefunctions.=<<END;
  297: var acts='';
  298: function rep_dirpath(suffix,val) {
  299:     eval("document.forms.dirpath"+suffix+".acts.value=val");
  300: }
  301: END
  302: 	if ($ENV{'form.catalogmode'} eq 'groupimport') {
  303:             $catalogmodefunctions.=<<END;
  304: function queue(val) {
  305:     if (eval("document.forms."+val+".filelink.checked")) {
  306: 	var l=val.length;
  307: 	var v=val.substring(4,l);
  308: 	document.forms.fileattr.acts.value+='1a'+v+'b';
  309:     }
  310:     else {
  311: 	var l=val.length;
  312: 	var v=val.substring(4,l);
  313: 	document.forms.fileattr.acts.value+='0a'+v+'b';
  314:     }
  315: }
  316: END
  317: 	}
  318: 
  319: # ---------------------------------------------------------------- Print Header
  320: 	$r->print(<<ENDHEADER);
  321: <html>
  322: <head>
  323: <title>The LearningOnline Network With CAPA Directory Browser</title>
  324: 
  325: <script type="text/javascript">
  326: $catalogmodefunctions
  327: function openWindow(url, wdwName, w, h, toolbar,scrollbar,locationbar) {
  328:     var xpos = (screen.width-w)/2;
  329:     xpos = (xpos < 0) ? '0' : xpos;
  330:     var ypos = (screen.height-h)/2-30;
  331:     ypos = (ypos < 0) ? '0' : ypos;
  332:     var options = "width=" + w + ",height=" + h + ",screenx="+xpos+",screeny="+ypos+",";
  333:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
  334:     options += "menubar=no,toolbar="+toolbar+",location="+locationbar+",directories=no";
  335:     var newWin = window.open(url, wdwName, options);
  336:     newWin.focus();
  337: }
  338: function gothere(val) {
  339:     window.location=val+'?acts='+document.forms.fileattr.acts.value;
  340: }
  341: </script>
  342: 
  343: </head>
  344: ENDHEADER
  345: my ($headerdom)=($uri=~/^\/res\/(\w+)\//);
  346: $r->print(&Apache::loncommon::bodytag('Browse Resources',undef,undef,undef,
  347: 				      $headerdom));
  348: # - Evaluate actions from previous page (both cumulatively and chronologically)
  349:         if ($ENV{'form.catalogmode'} eq 'groupimport') {
  350: 	    my $acts=$ENV{'form.acts'};
  351: 	    my @Acts=split(/b/,$acts);
  352: 	    my %ahash;
  353: 	    my %achash;
  354: 	    my $ac=0;
  355: 	    # some initial hashes for working with data
  356: 	    foreach (@Acts) {
  357: 		my ($state,$ref)=split(/a/);
  358: 		$ahash{$ref}=$state;
  359: 		$achash{$ref}=$ac;
  360: 		$ac++;
  361: 	    }
  362: 	    # sorting through the actions and changing the global database hash
  363: 	    foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
  364: 		my $key=$_;
  365: 		if ($ahash{$key} eq '1') {
  366: 		    $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
  367: 			$hash{'pre_'.$key.'_title'};
  368: 		    $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
  369: 			$hash{'storectr'}+0;
  370: 		    $hash{'storectr'}++;
  371: 		}
  372: 		if ($ahash{$key} eq '0') {
  373: 		    if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
  374: 			delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
  375: 		    }
  376: 		}
  377: 	    }
  378: 	    # deleting the previously cached listing
  379: 	    foreach (keys %hash) {
  380: 		if ($_ =~ /^pre_/ && $_ =~/link$/) {
  381: 		    my $key = $_;
  382: 		    $key =~ s/^pre_//;
  383: 		    $key =~ s/_[^_]*$//;
  384: 		    delete $hash{'pre_'.$key.'_title'};
  385: 		    delete $hash{'pre_'.$key.'_link'};
  386: 		}
  387: 	    }
  388: 	}
  389: 	
  390: # ---------------------------------- get state of file attributes to be showing
  391: 	if ($ENV{'form.attrs'}) {
  392: 	    for (my $i=0; $i<=9; $i++) {
  393: 		delete $hash{'display_attrs_'.$i};
  394: 		if ($ENV{'form.attr'.$i} == 1) {
  395: 		    $attrchk[$i] = 'checked';
  396: 		    $hash{'display_attrs_'.$i} = 1;
  397: 		}
  398: 	    }
  399: 	} else {
  400: 	    for (my $i=0; $i<=9; $i++) {
  401: 		$attrchk[$i] = 'checked' if $hash{'display_attrs_'.$i} == 1;
  402: 	    }
  403: 	}
  404: 
  405: # ------------------------------- output state of file attributes to be showing
  406: #                                 All versions has to the last item
  407: #                                 since it does not take an extra col
  408: 	my %lt=&Apache::lonlocal::texthash(
  409: 					   'ti' => 'Title',
  410: 					   'si' => 'Size',
  411: 					   'la' => 'Last access',
  412: 					   'lm' => 'Last modified',
  413: 					   'st' => 'Statistics',
  414: 					   'au' => 'Author',
  415: 					   'kw' => 'Keywords',
  416: 					   'ln' => 'Language',
  417: 					   'sr' => 'Show resource',
  418: 					   'av' => 'All versions',
  419: 					   'ud' => 'Update Display'
  420: 					   );
  421:         my $Displayfileattributes=&mt('Display file attributes');
  422: 	$r->print(<<END);
  423: <form method="post" name="fileattr" action="$uri"
  424:  enctype="application/x-www-form-urlencoded">
  425: <b><font color="#666666">$Displayfileattributes</font></b><br />
  426: <table border=0><tr>
  427: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] onClick="this.form.submit();" /> $lt{'ti'}</td>
  428: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] onClick="this.form.submit();" /> $lt{'si'}</td>
  429: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] onClick="this.form.submit();" /> $lt{'la'}</td>
  430: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] onClick="this.form.submit();" /> $lt{'lm'}</td>
  431: <td><input type="checkbox" name="attr8" value="1" $attrchk[8] onClick="this.form.submit();" /> $lt{'st'}</td>
  432: </tr><tr>
  433: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] onClick="this.form.submit();" /> $lt{'au'}</td>
  434: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] onClick="this.form.submit();" /> $lt{'kw'}</td>
  435: <td><input type="checkbox" name="attr6" value="1" $attrchk[6] onClick="this.form.submit();" /> $lt{'ln'}</td>
  436: <td><input type="checkbox" name="attr7" value="1" $attrchk[7] onClick="this.form.submit();" /> $lt{'sr'}</td>
  437: <td><input type="checkbox" name="attr9" value="1" $attrchk[9] onClick="this.form.submit();" /> $lt{'av'}</td>
  438: <td>&nbsp;</td>
  439: </tr></table>
  440: <input type="hidden" name="attrs" value="1" />
  441: <input type="submit" name="updatedisplay" value="$lt{'ud'}" />
  442: <input type="hidden" name="acts" value="" />
  443: $closebutton $groupimportbutton
  444: END
  445: # ---------------------------------------------------------------- Bread crumbs
  446:         $r->print(&Apache::lonhtmlcommon::crumbs($uri,'','',
  447: 				(($ENV{'form.catalogmode'} eq 'groupimport')?
  448: 				 'document.forms.fileattr':'')).
  449: 		  &Apache::lonhtmlcommon::select_recent('residx','resrecent',
  450: 'this.form.action=this.form.resrecent.options[this.form.resrecent.selectedIndex].value;this.form.submit();').
  451: 		  '</form>');
  452: # ------------------------------------------------------ Remember where we were
  453: 	&Apache::loncommon::storeresurl($uri);
  454: 	&Apache::lonhtmlcommon::store_recent('residx',$uri,$uri);
  455: # ----------------- output starting row to the indexed file/directory hierarchy
  456:         my $titleclr="#ddffff";
  457: #        $r->print(&initdebug());
  458: #        $r->print(&writedebug("Omit:@Omit")) if (@Omit);
  459: #        $r->print(&writedebug("Only:@Only")) if (@Only);
  460:         $r->print("<table width='100\%' border=0><tr><td bgcolor=#777777>\n");
  461: 	$r->print("<table width='100\%' border=0><tr bgcolor=$titleclr>\n");
  462: 	$r->print("<td $colspan><b>".&mt('Name')."</b></td>\n");
  463: 	$r->print("<td><b>".&mt('Title')."</b></td>\n") 
  464: 	    if ($hash{'display_attrs_0'} == 1);
  465: 	$r->print("<td align=right><b>".&mt("Size")." (".&mt("bytes").") ".
  466: 		  "</b></td>\n") if ($hash{'display_attrs_1'} == 1);
  467: 	$r->print("<td><b>".&mt("Last accessed")."</b></td>\n") 
  468: 	    if ($hash{'display_attrs_2'} == 1);
  469: 	$r->print("<td><b>".&mt("Last modified")."</b></td>\n")
  470: 	    if ($hash{'display_attrs_3'} == 1);
  471: 	$r->print("<td><b>".&mt("Author(s)")."</b></td>\n")
  472: 	    if ($hash{'display_attrs_4'} == 1);
  473: 	$r->print("<td><b>".&mt("Keywords")."</b></td>\n")
  474: 	    if ($hash{'display_attrs_5'} == 1);
  475: 	$r->print("<td><b>".&mt("Language")."</b></td>\n")
  476: 	    if ($hash{'display_attrs_6'} == 1);
  477: 	$r->print("<td><b>".&mt("Resource")."</b></td>\n")
  478: 	    if ($hash{'display_attrs_7'} == 1);
  479: 	$r->print("<td><b>".&mt("Usage Statistics")." <br />(".
  480: 		  &mt("Courses/Network Hits").")</b></td>\n")
  481: 	    if ($hash{'display_attrs_8'} == 1);
  482: 	$r->print('</tr>');
  483: 
  484: # ----------------- read in what directories have previously been set to "open"
  485: 	foreach (keys %hash) {
  486: 	    if ($_ =~ /^diropen_status_/) {
  487: 		my $key = $_;
  488: 		$key =~ s/^diropen_status_//;
  489: 		$dirs{$key} = $hash{$_};
  490: 	    }
  491: 	}
  492: 
  493: 	if ($ENV{'form.openuri'}) {  # take care of review and refresh options
  494: 	    my $uri=$ENV{'form.openuri'};
  495: 	    if (exists($hash{'diropen_status_'.$uri})) {
  496: 		my $cursta = $hash{'diropen_status_'.$uri};
  497: 		$dirs{$uri} = 'open';
  498: 		$hash{'diropen_status_'.$uri} = 'open';
  499: 		if ($cursta eq 'open') {
  500: 		    $dirs{$uri} = 'closed';
  501: 		    $hash{'diropen_status_'.$uri} = 'closed';
  502: 		}
  503: 	    } else {
  504: 		$hash{'diropen_status_'.$uri} = 'open';
  505: 		$dirs{$uri} = 'open';
  506: 	    }
  507: 	}
  508: 	
  509: 	my $toplevel;
  510: 	my $indent = 0;
  511: 	$uri = $uri.'/' if $uri !~ /.*\/$/;
  512: 
  513:  	if ($ENV{'form.dirPointer'} ne 'on') {
  514:  	    $hash{'top.level'} = $uri;
  515:  	    $toplevel = $uri;
  516:  	} else {
  517:  	    $toplevel = $hash{'top.level'};
  518:  	}
  519: 
  520: # -------------------------------- if not at top level, provide an uplink arrow
  521: 	if ($toplevel ne '/res/'){
  522: 	    my (@uri_com) = split(/\//,$uri);
  523: 	    pop @uri_com;
  524: 	    my $upone = join('/',@uri_com);
  525: 	    my @list = qw (0);
  526: 	    &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
  527: 	    $indent = 1;
  528: 	}
  529: 
  530: # -------- recursively go through all the directories and output as appropriate
  531: 	&scanDir ($r,$toplevel,$indent,\%hash);
  532: 	
  533: # ---------------------------- embed hidden information useful for group import
  534: 	$r->print("<form name='fnum'>");
  535: 	$r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
  536: 
  537: # -------------------------------------------------------------- end the tables
  538: 	$r->print('</table>');
  539: 	$r->print('</td></tr></table>');
  540: 
  541: # --------------------------------------------------- end the output and return
  542: 	$r->print('</body></html>'."\n");
  543:     }
  544:     if(! $c->aborted()) {
  545: # write back into the temporary file
  546: 	my %dbfile;
  547:         if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_NEWDB(),0640)) {
  548:             while (my($key,$value) = each(%hash)) {
  549:                 $dbfile{$key}=$value;
  550:             }
  551:             untie(%dbfile);
  552:         }
  553:     }
  554: 
  555:     return OK;
  556: }
  557: 
  558: # ----------------------------------------------- recursive scan of a directory
  559: sub scanDir {
  560:     my ($r,$startdir,$indent,$hashref)=@_;
  561:     my $c = $r->connection();
  562:     my ($compuri,$curdir);
  563:     my $dirptr=16384;
  564:     my $obs;
  565:     $indent++;
  566:     my %dupdirs = %dirs;
  567:     my @list=&get_list($r,$startdir);
  568:     foreach my $line (@list) {
  569:         return if ($c->aborted());
  570: 	#This is a kludge, sorry aboot this
  571: 	my ($strip,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs)=split(/\&/,$line,15); 
  572: 	next if($strip =~ /.*\.meta$/ | $obs eq '1');
  573: 	my (@fileparts) = split(/\./,$strip);
  574: 	if ($hash{'display_attrs_9'} != 1) {
  575: 	    if (scalar(@fileparts) >= 3) {
  576: 		my $fext = pop @fileparts;
  577: 		my $ov = pop @fileparts;
  578: 		my $fname = join ('.',@fileparts,$fext);
  579: 		next if (grep /\Q$fname\E/,@list and $ov =~ /^\d+$/);
  580: 	    }
  581: 	}
  582: 
  583: 	if ($dom eq 'domain') {
  584: 	    # dom list has full path /res/<domain name>/ already
  585: 	    $curdir='';
  586: 	    $compuri = (split(/\&/,$line))[0];
  587: 	} else {
  588: 	    # user, dir & file have name only, i.e., w/o path
  589: 	    $compuri = join('',$startdir,$strip,'/');
  590: 	    $curdir = $startdir;
  591: 	}
  592: 	my $diropen = 'closed';
  593: 	if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/)) {
  594: 	    while (my ($key,$val)= each %dupdirs) {
  595: 		if ($key eq $compuri and $val eq "open") {
  596: 		    $diropen = "opened";
  597: 		    delete($dupdirs{$key});
  598: 		    delete($dirs{$key});
  599: 		}
  600: 	    }
  601: 	}
  602: 	&display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
  603: 	&scanDir ($r,$compuri,$indent) if $diropen eq 'opened';
  604:     }
  605:     $indent--;
  606: }
  607: 
  608: # --------------- get complete matched list based on the uri (returns an array)
  609: sub get_list {
  610:     my ($r,$uri)=@_;
  611:     my @list;
  612:     (my $luri = $uri) =~ s/\//_/g;
  613:     if ($ENV{'form.updatedisplay'}) {
  614: 	foreach (keys %hash) {
  615: 	    delete $hash{$_} if ($_ =~ /^dirlist_files_/);
  616: 	}
  617:     }
  618: 
  619:     if ($hash{'dirlist_files_'.$luri}) {
  620: 	@list = split(/\n/,$hash{'dirlist_files_'.$luri});
  621:     } else {
  622: 	@list = &Apache::lonnet::dirlist($uri);
  623: 	$hash{'dirlist_files_'.$luri} = join("\n",@list);
  624:     }
  625:     @list=&match_ext($r,@list);
  626:     return @list;
  627: }
  628: 
  629: sub initdebug {
  630:     return <<ENDJS;
  631: <script>
  632: var debugging = true;
  633: if (debugging) {
  634:     var debuggingWindow = window.open('','Debug','width=400,height=300',true);
  635: } 
  636: 
  637: function output(text) {
  638:     if (debugging) {
  639:         debuggingWindow.document.writeln(text);
  640:     }
  641: }
  642: output("<html><head><title>Debugging Window</title></head><body><pre>");   
  643: </script>
  644: ENDJS
  645: }
  646: 
  647: sub writedebug {
  648:     my $text = shift;
  649:     return "<script>output('$text');</script>";
  650: }
  651: 
  652: # -------------------- filters out files based on extensions (returns an array)
  653: sub match_ext {
  654:     my ($r,@packlist)=@_;
  655:     my @trimlist;
  656:     my $nextline;
  657:     my @fileext;
  658:     my $dirptr=16384;
  659: 
  660:     foreach my $line (@packlist) {
  661: 	chomp $line;
  662: 	$line =~ s/^\/home\/httpd\/html//;
  663: 	my @unpackline = split (/\&/,$line);
  664: 	next if ($unpackline[0] eq '.');
  665: 	next if ($unpackline[0] eq '..');
  666: 	my @filecom = split (/\./,$unpackline[0]);
  667: 	my $fext = pop(@filecom);
  668: 	my $fnptr = $unpackline[3]&$dirptr;
  669:  	if ($fnptr == 0 and $unpackline[3] ne "") {
  670: 	    my $embstyle = &Apache::loncommon::fileembstyle($fext);
  671:             push @trimlist,$line if (defined($embstyle) && 
  672: 				     ($embstyle ne 'hdn' or $fext eq 'meta'));
  673: 	} else {
  674: 	    push @trimlist,$line;
  675: 	}
  676:     }
  677:     @trimlist = sort {uc($a) cmp uc($b)} (@trimlist);
  678:     return @trimlist;
  679: }
  680: 
  681: # ------------------------------- displays one line in appropriate table format
  682: sub display_line {
  683:     my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
  684:     my (@pathfn, $fndir);
  685:     my $dirptr=16384;
  686:     my $fileclr="#ffffe6";
  687:     my $iconpath= $r->dir_config('lonIconsURL') . '/';
  688: 
  689:     my @filecom = split (/\&/,$line);
  690:     my @pathcom = split (/\//,$filecom[0]);
  691:     my $listname = $pathcom[scalar(@pathcom)-1];
  692:     my $fnptr = $filecom[3]&$dirptr;
  693:     my $msg = &mt('View').' '.$filecom[0].' '.&mt('resources');
  694:     $msg = &mt('Close').' '.$filecom[0].' '.&mt('directory') if $diropen eq 'opened';
  695: 
  696:     my $tabtag='</td>';
  697:     my $i=0;
  698:     while ($i<=8) {
  699: 	$tabtag=join('',$tabtag,"<td>&nbsp;</td>")
  700: 	    if $hash{'display_attrs_'.$i} == 1;
  701: 	$i++;
  702:     }
  703: 	
  704:     my $valign = ($hash{'display_attrs_7'} == 1 ? 'top' : 'bottom');
  705: 
  706: # display uplink arrow
  707:     if ($filecom[1] eq 'viewOneUp') {
  708: 	$r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
  709: 	$r->print("<td>\n");
  710: 	$r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
  711: 		   '/" '.
  712: 		   'onSubmit="return rep_dirpath(\'UP\','.
  713: 		   'document.forms.fileattr.acts.value)" '.
  714: 		   'enctype="application/x-www-form-urlencoded"'.
  715:                    '>'."\n");
  716: 	$r->print ('<input type=hidden name=openuri value="'.
  717: 		   $startdir.'">'."\n");
  718: 	$r->print ('<input type="hidden" name="acts" value="">'."\n");
  719: 	$r->print ('<input src="'.$iconpath.'arrow_up.gif"');
  720: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  721: 		   "\n");
  722: 	$r->print(&mt("Up")." $tabtag</tr></form>\n");
  723: 	return OK;
  724:     }
  725: # Do we have permission to look at this?
  726: 
  727:     return OK if (!&Apache::lonnet::allowed('bre',$startdir.$filecom[0]));
  728: 
  729: # display domain
  730:     if ($filecom[1] eq 'domain') {
  731:  	$r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
  732:  	    if ($ENV{'form.dirPointer'} eq "on");
  733: 	$r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
  734: 	$r->print("<td>");
  735: 	&begin_form ($r,$filecom[0]);
  736: 	my $anchor = $filecom[0];
  737: 	$anchor =~ s/\///g;
  738: 	$r->print ('<a name="'.$anchor.'">');
  739: 	$r->print ('<input type="hidden" name="acts" value="">');
  740: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.
  741: 		   $diropen.'.gif"'); 
  742: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  743: 		   "\n");
  744: 	$r->print ('<a href="javascript:gothere(\''.$filecom[0].
  745: 		   '\')"><img src="'.$iconpath.'server.gif"');
  746: 	$r->print (' border="0" /></a>'."\n");
  747: 	$r->print (&mt("Domain")." - $listname ");
  748: 	if ($Apache::lonnet::domaindescription{$listname}) {
  749: 	    $r->print("(".$Apache::lonnet::domaindescription{$listname}.
  750: 		      ")");
  751: 	}
  752: 	$r->print (" $tabtag</tr></form>\n");
  753: 	return OK;
  754: 
  755: # display user directory
  756:     }
  757:     if ($filecom[1] eq 'user') {
  758: 	$r->print("<tr valign=$valign bgcolor=$fileclr>$extrafield");
  759: 	$r->print("<td nowrap>\n");
  760: 	my $curdir = $startdir.$filecom[0].'/';
  761: 	my $anchor = $curdir;
  762: 	$anchor =~ s/\///g;
  763: 	&begin_form ($r,$curdir);
  764: 	$r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
  765: 		   'whitespace1.gif" border="0" />'."\n");
  766: 	$r->print ('<input type="hidden" name="acts" value="">');
  767: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
  768: 		   '.gif"'); 
  769: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  770: 		   "\n");
  771: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
  772: 		   $iconpath.'quill.gif border="0" name="'.$msg.
  773: 		   '" height="22" /></a>');
  774: 	my $domain=(split(m|/|,$startdir))[2];
  775: 	my $plainname=&Apache::loncommon::plainname($listname,$domain);
  776: 	$r->print ($listname);
  777: 	if (defined($plainname) && $plainname) { $r->print(" ($plainname) "); }
  778: 	$r->print ($tabtag.'</tr></form>'."\n");
  779: 	return OK;
  780:     }
  781: 
  782: # display file
  783:     if ($fnptr == 0 and $filecom[3] ne '') {
  784: 	my $filelink = $startdir.$filecom[0];
  785: 	my @file_ext = split (/\./,$listname);
  786: 	my $curfext = $file_ext[-1];
  787:         if (@Omit) {
  788:             foreach (@Omit) { return OK if ($curfext eq $_); }
  789:         }
  790:         if (@Only) {
  791:             my $skip = 1;
  792:             foreach (@Only) { $skip = 0 if ($curfext eq $_); }
  793:             return OK if ($skip > 0);
  794:         }
  795: 	# Set the icon for the file
  796: 	my $iconname = &Apache::loncommon::icon($listname);
  797: 	$r->print("<tr valign='$valign' bgcolor=$fileclr><td nowrap>");
  798: 	my $metafile = grep /^\Q$filecom[0]\E\.meta\&/, @list;
  799: 	my $title;
  800:         if ($ENV{'form.catalogmode'} eq 'interactive') {
  801: 	    $title=$listname;
  802: 	    $title = &Apache::lonnet::metadata($filelink,'title')
  803: 		if ($metafile == 1);
  804: 	    $title=$listname unless $title;
  805: 	    my $titleesc=HTML::Entities::encode($title);
  806: 	    $titleesc=~s/\'/\\'/; #' (clean up this spare quote)
  807:             $r->print("<a href=\"javascript:select_data(\'",
  808:                       $titleesc,"','",$filelink,"')\">");
  809: 	    $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
  810: 		      "\n");
  811: 	    $r->print("</td><td nowrap>");
  812: 	}
  813:         elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
  814: 	    $title=$listname;
  815: 	    #$title = &Apache::lonnet::metadata($filelink,'title')
  816: 		#if ($metafile == 1);
  817: 	    $title=$listname unless $title;
  818: 	    my $titleesc=&HTML::Entities::encode($title);
  819: 	    $r->print("<form name='form$fnum'>\n");
  820: 	    $r->print("<input type='checkbox' name='filelink"."' ".
  821: 		      "value='$filelink' onClick='".
  822: 		      "javascript:queue(\"form$fnum\")' ");
  823: 	    if ($hash{'store_'.$filelink}) {
  824: 		$r->print("checked");
  825: 	    }
  826: 	    $r->print(">\n");
  827: 	    $r->print("<input type='hidden' name='title"."' ".
  828: 		      "value='$titleesc'>\n");
  829: 	    $r->print("</form>\n");
  830: 	    $r->print("</td><td nowrap>");
  831: 	    $hash{"pre_${fnum}_link"}=$filelink;
  832: 	    $hash{"pre_${fnum}_title"}=$titleesc;
  833:   	    $fnum++;
  834: 	}
  835: 
  836: 	if ($indent > 0 and $indent < 11) {
  837: 	    $r->print("<img src=",$iconpath,"whitespace",$indent,
  838: 		      ".gif border='0' />\n");
  839: 	} elsif ($indent >0) {
  840: 	    my $ten = int($indent/10.);
  841: 	    my $rem = $indent%10.0;
  842: 	    my $count = 0;
  843: 	    while ($count < $ten) {
  844: 		$r->print("<img src=",$iconpath,
  845: 			  "whitespace10.gif border='0' />\n");
  846: 	    $count++;
  847: 	    }
  848: 	    $r->print("<img src=",$iconpath,"whitespace",$rem,
  849: 		      ".gif border='0' />\n") if $rem > 0;
  850: 	}
  851: 
  852: 	$r->print("<img src='$iconname' border='0' />\n");
  853: 	$r->print (" <a href=\"javascript:openWindow('".$filelink.
  854: 		   "', 'previewfile', '450', '500', 'no', 'yes','yes')\";".
  855: 		   " TARGET=_self>$listname</a> ");
  856: 
  857: 	$r->print (" (<a href=\"javascript:openWindow('".$filelink.
  858: 		   ".meta', 'metadatafile', '500', '550', 'no', 'yes','no')\"; ".
  859: 		   "TARGET=_self>metadata</a>) ") if ($metafile == 1);
  860: 
  861: 	$r->print("</td>\n");
  862: 	if ($hash{'display_attrs_0'} == 1) {
  863: 	    my $title = &Apache::lonnet::gettitle($filelink,'title')
  864: 		if ($metafile == 1);
  865: 	    $r->print('<td> '.($title eq '' ? '&nbsp;' : $title).
  866: 		      ' </td>'."\n");
  867: 	}
  868: 	$r->print('<td align=right> ',
  869: 		  $filecom[8]," </td>\n") 
  870: 	    if $hash{'display_attrs_1'} == 1;
  871: 	$r->print('<td> '.
  872: 		  (localtime($filecom[9]))." </td>\n") 
  873: 	    if $hash{'display_attrs_2'} == 1;
  874: 	$r->print('<td> '.
  875: 		  (localtime($filecom[10]))." </td>\n") 
  876: 	    if $hash{'display_attrs_3'} == 1;
  877: 
  878: 	if ($hash{'display_attrs_4'} == 1) {
  879: 	    my $author = &Apache::lonnet::metadata($filelink,'author')
  880: 		if ($metafile == 1);
  881: 	    $r->print('<td> '.($author eq '' ? '&nbsp;' : $author).
  882: 		      " </td>\n");
  883: 	}
  884: 	if ($hash{'display_attrs_5'} == 1) {
  885: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
  886: 		if ($metafile == 1);
  887: 	    # $keywords = '&nbsp;' if (!$keywords);
  888: 	    $r->print('<td> '.($keywords eq '' ? '&nbsp;' : $keywords).
  889: 		      " </td>\n");
  890: 	}
  891: 	if ($hash{'display_attrs_6'} == 1) {
  892: 	    my $lang = &Apache::lonnet::metadata($filelink,'language')
  893: 		if ($metafile == 1);
  894: 	    $lang = &Apache::loncommon::languagedescription($lang);
  895: 	    $r->print('<td> '.($lang eq '' ? '&nbsp;' : $lang).
  896: 		      " </td>\n");
  897: 	}
  898:         if ($hash{'display_attrs_7'} == 1) {
  899:             my $output='';
  900:             my $embstyle=&Apache::loncommon::fileembstyle($curfext);
  901: 	    if ($embstyle eq 'ssi') {
  902: 		my $cache=$Apache::lonnet::perlvar{'lonDocRoot'}.$filelink.
  903: 		    '.tmp';
  904: 		if ((!$ENV{'form.updatedisplay'}) &&
  905: 		    (-e $cache)) {
  906: 		    open(FH,$cache);
  907: 		    $output=join("\n",<FH>);
  908: 		    close(FH);
  909: 		} else {
  910: 		    $output=&Apache::lonnet::ssi_body($filelink);
  911: 		    open(FH,">$cache");
  912: 		    print FH $output;
  913: 		    close(FH);
  914: 		}
  915: 		$output='<font size="-2">'.$output.'</font>';
  916: 	   } elsif ($embstyle eq 'img') {
  917:                $output='<img src="'.$filelink.'" />';
  918:            } elsif ($filelink=~/^\/res\/(\w+)\/(\w+)\//) {
  919:                $output='<img src="http://'.
  920: 		 $Apache::lonnet::hostname{&Apache::lonnet::homeserver($2,$1)}.
  921:                  '/cgi-bin/thumbnail.gif?url='.$filelink.'" />';
  922:            }
  923: 	   $r->print('<td> '.($output eq '' ? '&nbsp;':$output).
  924: 		      " </td>\n");
  925:         }
  926: 	if ($hash{'display_attrs_8'} == 1) {
  927: 	    my (%stat) = &Apache::lonmeta::dynamicmeta($filelink) if ($metafile == 1);
  928: 	    my $stat = (exists($stat{'course'}) ? $stat{'course'} : '').
  929: 		((exists($stat{'course'}) || exists($stat{'count'})) ? '/' : '').
  930: 		(exists($stat{'count'}) ? $stat{'count'} : '');
  931: 	    $r->print('<td align=center> '.($stat eq '' ? '&nbsp;' : $stat).
  932: 		      ' </td>'."\n");
  933: 	}
  934: 
  935: 	$r->print("</tr>\n");
  936:     }
  937: 
  938: # -- display directory
  939:     if ($fnptr == $dirptr) {
  940: 	my $curdir = $startdir.$filecom[0].'/';
  941: 	my $anchor = $curdir;
  942: 	$anchor =~ s/\///g;
  943: 	$r->print("<tr bgcolor=$fileclr>$extrafield<td valign=$valign>");
  944: 	&begin_form ($r,$curdir);
  945: 	my $indentm1 = $indent-1;
  946: 	if ($indentm1 < 11 and $indentm1 > 0) {
  947: 	    $r->print("<img src=",$iconpath,"whitespace",$indentm1,
  948: 		      ".gif border='0' />\n");
  949: 	} else {
  950: 	    my $ten = int($indentm1/10.);
  951: 	    my $rem = $indentm1%10.0;
  952: 	    my $count = 0;
  953: 	    while ($count < $ten) {
  954: 		$r->print ("<img src=",$iconpath
  955: 			   ,"whitespace10.gif border='0' />\n");
  956: 		$count++;
  957: 	    }
  958: 	    $r->print ("<img src=",$iconpath,"whitespace",$rem,
  959: 		       ".gif border='0' />\n") if $rem > 0;
  960: 	}
  961: 	$r->print ('<input type="hidden" name="acts" value="">');
  962: 	$r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
  963: 		   'folder_pointer_'.$diropen.'.gif"');
  964: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  965: 		   "\n");
  966: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
  967: 		   $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
  968: 		   "\n");
  969: 	$r->print ("$listname</td>\n");
  970: # Attributes
  971: 	my $filelink = $startdir.$filecom[0].'/default';
  972: 
  973: 	if ($hash{'display_attrs_0'} == 1) {
  974: 	    my $title = &Apache::lonnet::gettitle($filelink,'title');
  975: 	    $r->print('<td> '.($title eq '' ? '&nbsp;' : $title).
  976: 		      ' </td>'."\n");
  977: 	}
  978: 	$r->print('<td align=right> ',
  979: 		  $filecom[8]," </td>\n") 
  980: 	    if $hash{'display_attrs_1'} == 1;
  981: 	$r->print('<td> '.
  982: 		  (localtime($filecom[9]))." </td>\n") 
  983: 	    if $hash{'display_attrs_2'} == 1;
  984: 	$r->print('<td> '.
  985: 		  (localtime($filecom[10]))." </td>\n") 
  986: 	    if $hash{'display_attrs_3'} == 1;
  987: 
  988: 	if ($hash{'display_attrs_4'} == 1) {
  989: 	    my $author = &Apache::lonnet::metadata($filelink,'author');
  990: 	    $r->print('<td> '.($author eq '' ? '&nbsp;' : $author).
  991: 		      " </td>\n");
  992: 	}
  993: 	if ($hash{'display_attrs_5'} == 1) {
  994: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
  995: 	    # $keywords = '&nbsp;' if (!$keywords);
  996: 	    $r->print('<td> '.($keywords eq '' ? '&nbsp;' : $keywords).
  997: 		      " </td>\n");
  998: 	}
  999: 	if ($hash{'display_attrs_6'} == 1) {
 1000: 	    my $lang = &Apache::lonnet::metadata($filelink,'language');
 1001: 	    $lang = &Apache::loncommon::languagedescription($lang);
 1002: 	    $r->print('<td> '.($lang eq '' ? '&nbsp;' : $lang).
 1003: 		      " </td>\n");
 1004: 	}
 1005:         if ($hash{'display_attrs_7'} == 1) {
 1006: 	   $r->print('<td>&nbsp;</td>');
 1007:         }
 1008: 	if ($hash{'display_attrs_8'} == 1) {
 1009: 	   $r->print('<td>&nbsp;</td>');
 1010: 	}
 1011: 	$r->print('</form></tr>');
 1012:     }
 1013: 
 1014: }
 1015: 
 1016: # ------------------- prints the beginning of a form for directory or file link
 1017: sub begin_form {
 1018:     my ($r,$uri) = @_;
 1019:     my $anchor = $uri;
 1020:     $anchor =~ s/\///g;
 1021:     $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
 1022: 	       '#'.$anchor.
 1023: 	       '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
 1024: 	       ',document.forms.fileattr.acts.value)" '.
 1025: 	       'enctype="application/x-www-form-urlencoded">'."\n");
 1026:     $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
 1027: 	       "\n");
 1028:     $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
 1029:     $dnum++;
 1030: }
 1031: 
 1032: # --------- settings whenever the user causes the indexer window to be launched
 1033: sub start_fresh_session {
 1034:     delete $hash{'form.catalogmode'};
 1035:     delete $hash{'form.mode'};
 1036:     delete $hash{'form.form'};
 1037:     delete $hash{'form.element'};
 1038:     delete $hash{'form.omit'};
 1039:     delete $hash{'form.only'};
 1040:     foreach (keys %hash) {
 1041:         delete $hash{$_} if (/^(pre_|store)/);
 1042:     }
 1043: }
 1044: 
 1045: # ------------------------------------------------------------------- setvalues
 1046: sub setvalues {
 1047:     # setvalues is used in registerurl to synchronize the database
 1048:     # hash and environment hashes
 1049:     my ($H1,$h1key,$H2,$h2key) =@_;
 1050:     #
 1051:     if (exists $H2->{$h2key}) {
 1052: 	$H1->{$h1key} = $H2->{$h2key};
 1053:     } elsif (exists $H1->{$h1key}) {
 1054: 	$H2->{$h2key} = $H1->{$h1key};
 1055:     } 
 1056: }
 1057: 
 1058: 1;
 1059: 
 1060: sub cleanup {
 1061:     if (tied(%hash)){
 1062: 	&Apache::lonnet::logthis('Cleanup indexer: hash');
 1063:     }
 1064: }
 1065: 
 1066: =head1 NAME
 1067: 
 1068: Apache::lonindexer - mod_perl module for cross server filesystem browsing
 1069: 
 1070: =head1 SYNOPSIS
 1071: 
 1072: Invoked by /etc/httpd/conf/srm.conf:
 1073: 
 1074:  <LocationMatch "^/res.*/$">
 1075:  SetHandler perl-script
 1076:  PerlHandler Apache::lonindexer
 1077:  </LocationMatch>
 1078: 
 1079: =head1 INTRODUCTION
 1080: 
 1081: This module enables a scheme of browsing across a cross server.
 1082: 
 1083: This is part of the LearningOnline Network with CAPA project
 1084: described at http://www.lon-capa.org.
 1085: 
 1086: =head1 BEGIN SUBROUTINE
 1087: 
 1088: This routine is only run once after compilation.
 1089: 
 1090: =over 4
 1091: 
 1092: =item *
 1093: 
 1094: Initializes %language hash table.
 1095: 
 1096: =back
 1097: 
 1098: =head1 HANDLER SUBROUTINE
 1099: 
 1100: This routine is called by Apache and mod_perl.
 1101: 
 1102: =over 4
 1103: 
 1104: =item *
 1105: 
 1106: read in machine configuration variables
 1107: 
 1108: =item *
 1109: 
 1110: see if called from an interactive mode
 1111: 
 1112: =item *
 1113: 
 1114: refresh environment with user database values (in %hash)
 1115: 
 1116: =item *
 1117: 
 1118: define extra fields and buttons in case of special mode
 1119: 
 1120: =item *
 1121: 
 1122: set catalogmodefunctions to have extra needed javascript functionality
 1123: 
 1124: =item *
 1125: 
 1126: print header
 1127: 
 1128: =item *
 1129: 
 1130: evaluate actions from previous page (both cumulatively and chronologically)
 1131: 
 1132: =item *
 1133: 
 1134: output title
 1135: 
 1136: =item *
 1137: 
 1138: get state of file attributes to be showing
 1139: 
 1140: =item *
 1141: 
 1142: output state of file attributes to be showing
 1143: 
 1144: =item *
 1145: 
 1146: output starting row to the indexed file/directory hierarchy
 1147: 
 1148: =item *
 1149: 
 1150: read in what directories have previously been set to "open"
 1151: 
 1152: =item *
 1153: 
 1154: if not at top level, provide an uplink arrow
 1155: 
 1156: =item *
 1157: 
 1158: recursively go through all the directories and output as appropriate
 1159: 
 1160: =item *
 1161: 
 1162: information useful for group import
 1163: 
 1164: =item *
 1165: 
 1166: end the tables
 1167: 
 1168: =item *
 1169: 
 1170: end the output and return
 1171: 
 1172: =back
 1173: 
 1174: =head1 OTHER SUBROUTINES
 1175: 
 1176: =over 4
 1177: 
 1178: =item *
 1179: 
 1180: scanDir - recursive scan of a directory
 1181: 
 1182: =item *
 1183: 
 1184: get_list - get complete matched list based on the uri (returns an array)
 1185: 
 1186: =item *
 1187: 
 1188: match_ext - filters out files based on extensions (returns an array)
 1189: 
 1190: =item *
 1191: 
 1192: display_line - displays one line in appropriate table format
 1193: 
 1194: =item *
 1195: 
 1196: begin_form - prints the beginning of a form for directory or file link
 1197: 
 1198: =item *
 1199: 
 1200: start_fresh_session - settings whenever the user causes the indexer window
 1201: to be launched
 1202: 
 1203: =back
 1204: 
 1205: =cut

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>