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

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

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