Annotation of loncom/interface/lonindexer.pm, revision 1.74

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

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