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

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

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