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

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

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