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

1.1       www         1: # The LearningOnline Network with CAPA
1.24      harris41    2: # Directory Indexer
                      3: #
1.115   ! www         4: # $Id: lonindexer.pm,v 1.114 2004/06/17 20:43:04 www 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.109     taceyjo1   55: use Apache::lonsource();
1.2       harris41   56: use GDBM_File;
                     57: 
1.23      harris41   58: # ---------------------------------------- variables used throughout the module
1.87      www        59: my %hash; # global user-specific gdbm file
1.17      harris41   60: my %dirs; # keys are directories, values are the open/close status
                     61: my %language; # has the reference information present in language.tab
1.111     www        62: my %dynhash; # hash of hashes for dynamic metadata
1.113     www        63: my %fieldnames; # Metadata fieldnames
1.17      harris41   64: # ----- Values which are set by the handler subroutine and are accessible to
                     65: # -----     other methods.
                     66: my $extrafield; # default extra table cell
                     67: my $fnum; # file counter
                     68: my $dnum; # directory counter
1.1       www        69: 
1.40      matthew    70: # ----- Used to include or exclude files with certain extensions.
1.43      matthew    71: my @Only = ();
1.40      matthew    72: my @Omit = ();
                     73: 
                     74: 
1.23      harris41   75: # ----------------------------- Handling routine called via Apache and mod_perl
1.1       www        76: sub handler {
                     77:     my $r = shift;
1.67      matthew    78:     my $c = $r->connection();
1.76      www        79:     &Apache::loncommon::content_type($r,'text/html');
1.50      albertel   80:     &Apache::loncommon::no_cache($r);
1.1       www        81:     $r->send_http_header;
                     82:     return OK if $r->header_only;
1.9       harris41   83:     $fnum=0;
1.16      harris41   84:     $dnum=0;
1.17      harris41   85: 
1.43      matthew    86:     # Deal with stupid global variables (is there a way around making
                     87:     # these global to this package?  It is just so wrong....)
                     88:     undef (@Only);
                     89:     undef (@Omit);
1.113     www        90:     %fieldnames=&Apache::lonmeta::fieldnames();
1.43      matthew    91: 
1.23      harris41   92: # ------------------------------------- read in machine configuration variables
1.10      harris41   93:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.1       www        94:     my $domain  = $r->dir_config('lonDefDomain');
                     95:     my $role    = $r->dir_config('lonRole');
                     96:     my $loadlim = $r->dir_config('lonLoadLim');
                     97:     my $servadm = $r->dir_config('lonAdmEMail');
                     98:     my $sysadm  = $r->dir_config('lonSysEMail');
                     99:     my $lonhost = $r->dir_config('lonHostID');
                    100:     my $tabdir  = $r->dir_config('lonTabDir');
                    101: 
1.7       harris41  102:     my $fileclr='#ffffe6';
1.15      harris41  103:     my $line;
                    104:     my (@attrchk,@openpath);
                    105:     my $uri=$r->uri;
                    106: 
1.7       harris41  107: # -------------------------------------- see if called from an interactive mode
1.35      matthew   108:     # Get the parameters from the query string
1.36      matthew   109:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.40      matthew   110: 	     ['catalogmode','launch','acts','mode','form','element',
1.79      albertel  111:               'only','omit','titleelement']);
1.35      matthew   112:     #-------------------------------------------------------------------
1.17      harris41  113:     my $closebutton='';
1.7       harris41  114:     my $groupimportbutton='';
                    115:     my $colspan=''; 
1.14      harris41  116: 
                    117:     $extrafield='';
1.17      harris41  118:     my $diropendb = 
1.66      albertel  119: 	"/home/httpd/perl/tmp/$ENV{'user.domain'}_$ENV{'user.name'}_indexer.db";
1.67      matthew   120:     %hash = ();
1.68      albertel  121:     {
                    122: 	my %dbfile;
1.87      www       123: 	if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_READER(),0640)) {
1.68      albertel  124: 	    while(my($key,$value)=each(%dbfile)) {
                    125: 		$hash{$key}=$value;
                    126: 	    }
                    127: 	    untie(%dbfile);
                    128: 	}
                    129:     }
                    130:     {
1.15      harris41  131: 	if ($ENV{'form.launch'} eq '1') {
1.17      harris41  132: 	    &start_fresh_session();
1.105     taceyjo1  133:    }
                    134:   #Hijack lonindexer to verify a title and be close down.
                    135:    if ($ENV{'form.launch'} eq '2') {
1.108     albertel  136:        $r->content_type('text/html');
                    137:        my $extra='';
                    138:        if (defined($ENV{'form.titleelement'})) {
                    139: 	   my $verify_title = &Apache::lonnet::gettitle($ENV{'form.acts'});
1.113     www       140: #	   &Apache::lonnet::logthis("Hrrm $ENV{'form.acts'} -- $verify_title");
1.108     albertel  141: 	   $verify_title=~s/'/\\'/g;
                    142: 	   $extra='window.opener.document.forms["'.$ENV{'form.form'}.'"].elements["'.$ENV{'form.titleelement'}.'"].value=\''.$verify_title.'\';';
                    143:        }
                    144:        $r->print(<<ENDSUBM);
1.105     taceyjo1  145: 		<html>
                    146: 		<script type="text/javascript">
                    147: 		function load() {
                    148: 			window.opener.document.forms["$ENV{'form.form'}"].elements["$ENV{'form.element'}"].value='$ENV{'form.acts'}';
1.108     albertel  149: 			$extra
1.105     taceyjo1  150: 			window.close();
                    151: 		}
                    152:    	</script>
                    153:     	<body onLoad=load();>
                    154:      	</body>
                    155:     	</html>
                    156: ENDSUBM
1.108     albertel  157:        return OK;
1.105     taceyjo1  158:    }
                    159:     
1.17      harris41  160: # -------------------- refresh environment with user database values (in %hash)
1.48      matthew   161: 	&setvalues(\%hash,'form.catalogmode',\%ENV,'form.catalogmode'   );
1.15      harris41  162: 
1.17      harris41  163: # --------------------- define extra fields and buttons in case of special mode
1.15      harris41  164: 	if ($ENV{'form.catalogmode'} eq 'interactive') {
                    165: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
                    166: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17      harris41  167: 		' border="0" /></td>';
1.15      harris41  168: 	    $colspan=" colspan='2' ";
1.77      www       169:             my $cl=&mt('Close');
1.15      harris41  170:             $closebutton=<<END;
1.77      www       171: <input type="button" name="close" value='$cl' onClick="self.close()">
1.7       harris41  172: END
1.16      harris41  173:         }
1.15      harris41  174: 	elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
                    175: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
                    176: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17      harris41  177: 		' border="0" /></td>';
1.15      harris41  178: 	    $colspan=" colspan='2' ";
1.77      www       179: 	    my $cl=&mt('Close');
                    180:             my $gi=&mt('Group Import');
1.15      harris41  181:             $closebutton=<<END;
1.77      www       182: <input type="button" name="close" value='$cl' onClick="self.close()">
1.7       harris41  183: END
1.15      harris41  184:             $groupimportbutton=<<END;
1.77      www       185: <input type="button" name="groupimport" value='$gi'
1.17      harris41  186: onClick="javascript:select_group()">
1.7       harris41  187: END
1.15      harris41  188:         }
1.35      matthew   189: 	# Additions made by Matthew to make the browser a little easier to deal
                    190: 	# with in the future.
                    191: 	#
                    192: 	# $mode (at this time) indicates if we are in edit mode.
                    193: 	# $form is the name of the form that the URL is placed when the
                    194: 	#       selection is made.
                    195: 	# $element is the name of the element in $formname which receives
                    196: 	#       the URL.
1.91      taceyjo1  197: 	#&Apache::lonxml::debug('Checking mode, form, element');
1.79      albertel  198: 	&setvalues(\%hash,'form.mode'        ,\%ENV,'form.mode'   );
                    199: 	&setvalues(\%hash,'form.form'        ,\%ENV,'form.form'   );
                    200: 	&setvalues(\%hash,'form.element'     ,\%ENV,'form.element');
                    201: 	&setvalues(\%hash,'form.titleelement',\%ENV,'form.titleelement');
                    202: 	&setvalues(\%hash,'form.only'        ,\%ENV,'form.only'   );
                    203: 	&setvalues(\%hash,'form.omit'        ,\%ENV,'form.omit'   );
1.35      matthew   204: 
1.40      matthew   205:         # Deal with 'omit' and 'only' 
                    206:         if (exists $ENV{'form.omit'}) {
                    207:             @Omit = split(',',$ENV{'form.omit'});
                    208:         }
                    209:         if (exists $ENV{'form.only'}) {
                    210:             @Only = split(',',$ENV{'form.only'});
                    211:         }
                    212:         
1.35      matthew   213: 	my $mode = $ENV{'form.mode'};
1.79      albertel  214: 	my ($form,$element,$titleelement);
1.39      matthew   215: 	if ($mode eq 'edit' || $mode eq 'parmset') {
1.79      albertel  216: 	    $form         = $ENV{'form.form'};
                    217: 	    $element      = $ENV{'form.element'};
                    218: 	    $titleelement = $ENV{'form.titleelement'};
1.35      matthew   219: 	}
1.90      taceyjo1  220: 	#&Apache::lonxml::debug("mode=$mode form=$form element=$element titleelement=$titleelement");
1.17      harris41  221: # ------ set catalogmodefunctions to have extra needed javascript functionality
1.15      harris41  222: 	my $catalogmodefunctions='';
                    223: 	if ($ENV{'form.catalogmode'} eq 'interactive' or
                    224: 	    $ENV{'form.catalogmode'} eq 'groupimport') {
1.35      matthew   225: 	    # The if statement below sets us up to use the old version
                    226: 	    # by default (ie. if $mode is undefined).  This is the easy
                    227: 	    # way out.  Hopefully in the future I'll find a way to get 
                    228: 	    # the calls dealt with in a more comprehensive manner.
1.41      www       229: 
                    230: #
                    231: # There is now also mode "simple", which is for the simple version of the rat
                    232: #
                    233: #
1.39      matthew   234: 	    if (!defined($mode) || ($mode ne 'edit' && $mode ne 'parmset')) {
1.40      matthew   235:                 my $location = "/adm/groupsort?catalogmode=groupimport&";
1.41      www       236:                 $location .= "mode=".$mode."&";
1.40      matthew   237:                 $location .= "acts=";
1.35      matthew   238: 		$catalogmodefunctions=<<"END";
1.108     albertel  239: function select_data(url) {
1.7       harris41  240:     changeURL(url);
1.8       harris41  241:     self.close();
                    242: }
                    243: function select_group() {
1.40      matthew   244:     window.location="$location"+document.forms.fileattr.acts.value;
1.16      harris41  245: }
1.35      matthew   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
1.108     albertel  259: function select_data(url) {
                    260:    var location = "/res/?launch=2&form=$form&element=$element&titleelement=$titleelement&acts=" + url;
1.105     taceyjo1  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
1.108     albertel  293: function select_data(url) {
1.39      matthew   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.111     www       412: 	    for (my $i=0; $i<=11; $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.111     www       420: 	    for (my $i=0; $i<=11; $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.109     taceyjo1  437: 					   'sa' => 'Source Available',
1.77      www       438: 					   'sr' => 'Show resource',
1.111     www       439: 					   'li' => 'Linked/Related Resources',
1.77      www       440: 					   'av' => 'All versions',
                    441: 					   'ud' => 'Update Display'
                    442: 					   );
1.15      harris41  443: 	$r->print(<<END);
1.17      harris41  444: <form method="post" name="fileattr" action="$uri"
                    445:  enctype="application/x-www-form-urlencoded">
1.115   ! www       446: <input type="checkbox" name="attr9" value="1" $attrchk[9] onClick="this.form.submit();" /> $lt{'av'}
        !           447: <table border="0">
        !           448: <tr>
1.87      www       449: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] onClick="this.form.submit();" /> $lt{'ti'}</td>
1.115   ! www       450: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] onClick="this.form.submit();" /> $lt{'au'}</td>
        !           451: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] onClick="this.form.submit();" /> $lt{'kw'}</td>
        !           452: <td><input type="checkbox" name="attr6" value="1" $attrchk[6] onClick="this.form.submit();" /> $lt{'ln'}</td>
        !           453: </tr>
        !           454: <tr>
1.87      www       455: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] onClick="this.form.submit();" /> $lt{'si'}</td>
                    456: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] onClick="this.form.submit();" /> $lt{'la'}</td>
                    457: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] onClick="this.form.submit();" /> $lt{'lm'}</td>
1.115   ! www       458: <td><input type="checkbox" name="attr10" value="1" $attrchk[10] onClick="this.form.submit();" /> $lt{'sa'}</td>
        !           459: </tr>
        !           460: <tr>
1.87      www       461: <td><input type="checkbox" name="attr8" value="1" $attrchk[8] onClick="this.form.submit();" /> $lt{'st'}</td>
1.115   ! www       462: <td><input type="checkbox" name="attr11" value="1" $attrchk[11] onClick="this.form.submit();" /> $lt{'li'}</td>
1.87      www       463: <td><input type="checkbox" name="attr7" value="1" $attrchk[7] onClick="this.form.submit();" /> $lt{'sr'}</td>
1.115   ! www       464: <td>&nbsp;</td>
        !           465: </tr>
        !           466: </table>
1.87      www       467: <input type="hidden" name="attrs" value="1" />
                    468: <input type="submit" name="updatedisplay" value="$lt{'ud'}" />
1.16      harris41  469: <input type="hidden" name="acts" value="" />
1.87      www       470: $closebutton $groupimportbutton
1.1       www       471: END
1.97      www       472: # -------------- Filter out sequence containment in crumbs and "recent folders"
                    473: 	my $storeuri=$uri;
                    474: 	$storeuri='/'.(split(/\.(page|sequence)\/\//,$uri))[-1];
                    475: 	$storeuri=~s/\/+/\//g;
1.82      www       476: # ---------------------------------------------------------------- Bread crumbs
1.97      www       477:         $r->print(&Apache::lonhtmlcommon::crumbs($storeuri,'','',
1.87      www       478: 				(($ENV{'form.catalogmode'} eq 'groupimport')?
                    479: 				 'document.forms.fileattr':'')).
                    480: 		  &Apache::lonhtmlcommon::select_recent('residx','resrecent',
1.100     www       481: 'this.form.action=this.form.resrecent.options[this.form.resrecent.selectedIndex].value;this.form.submit();'));
                    482: # -------------------------------------------------------- Resource Home Button
                    483: 	my $reshome=$ENV{'course.'.$ENV{'request.course.id'}.'.reshome'};
                    484: 	if ($reshome) {
                    485: 	    $r->print("<font size='+2'><a href='");
                    486: 	    if ($ENV{'form.catalogmode'} eq 'groupimport') {
                    487: 		$r->print('javascript:document.forms.fileattr.action="'.$reshome.'";document.forms.fileattr.submit();');
                    488: 	    } else {
                    489: 		$r->print($reshome);
                    490: 	    }
                    491: 	    $r->print("'>".&mt('Home').'</a></font>');
                    492: 	}
                    493: 	$r->print('</form>');
1.85      www       494: # ------------------------------------------------------ Remember where we were
1.97      www       495: 	&Apache::loncommon::storeresurl($storeuri);
                    496: 	&Apache::lonhtmlcommon::store_recent('residx',$storeuri,$storeuri);
1.23      harris41  497: # ----------------- output starting row to the indexed file/directory hierarchy
1.15      harris41  498:         my $titleclr="#ddffff";
1.40      matthew   499: #        $r->print(&initdebug());
                    500: #        $r->print(&writedebug("Omit:@Omit")) if (@Omit);
                    501: #        $r->print(&writedebug("Only:@Only")) if (@Only);
1.46      ng        502:         $r->print("<table width='100\%' border=0><tr><td bgcolor=#777777>\n");
1.45      ng        503: 	$r->print("<table width='100\%' border=0><tr bgcolor=$titleclr>\n");
1.77      www       504: 	$r->print("<td $colspan><b>".&mt('Name')."</b></td>\n");
                    505: 	$r->print("<td><b>".&mt('Title')."</b></td>\n") 
1.45      ng        506: 	    if ($hash{'display_attrs_0'} == 1);
1.77      www       507: 	$r->print("<td align=right><b>".&mt("Size")." (".&mt("bytes").") ".
1.45      ng        508: 		  "</b></td>\n") if ($hash{'display_attrs_1'} == 1);
1.77      www       509: 	$r->print("<td><b>".&mt("Last accessed")."</b></td>\n") 
1.17      harris41  510: 	    if ($hash{'display_attrs_2'} == 1);
1.77      www       511: 	$r->print("<td><b>".&mt("Last modified")."</b></td>\n")
1.17      harris41  512: 	    if ($hash{'display_attrs_3'} == 1);
1.77      www       513: 	$r->print("<td><b>".&mt("Author(s)")."</b></td>\n")
1.17      harris41  514: 	    if ($hash{'display_attrs_4'} == 1);
1.77      www       515: 	$r->print("<td><b>".&mt("Keywords")."</b></td>\n")
1.17      harris41  516: 	    if ($hash{'display_attrs_5'} == 1);
1.77      www       517: 	$r->print("<td><b>".&mt("Language")."</b></td>\n")
1.45      ng        518: 	    if ($hash{'display_attrs_6'} == 1);
1.77      www       519: 	$r->print("<td><b>".&mt("Usage Statistics")." <br />(".
                    520: 		  &mt("Courses/Network Hits").")</b></td>\n")
1.70      ng        521: 	    if ($hash{'display_attrs_8'} == 1);
1.109     taceyjo1  522: 	$r->print("<td><b>".&mt("Source Available")."</b></td>\n")
                    523: 	    if ($hash{'display_attrs_10'} == 1);
1.111     www       524: 	$r->print("<td><b>".&mt("Linked/Related Resources")."</b></td>\n")
                    525: 	    if ($hash{'display_attrs_11'} == 1);
1.115   ! www       526: 	$r->print("<td><b>".&mt("Resource")."</b></td>\n")
        !           527: 	    if ($hash{'display_attrs_7'} == 1);
1.45      ng        528: 	$r->print('</tr>');
1.5       harris41  529: 
1.23      harris41  530: # ----------------- read in what directories have previously been set to "open"
1.27      harris41  531: 	foreach (keys %hash) {
1.4       harris41  532: 	    if ($_ =~ /^diropen_status_/) {
                    533: 		my $key = $_;
                    534: 		$key =~ s/^diropen_status_//;
                    535: 		$dirs{$key} = $hash{$_};
                    536: 	    }
1.27      harris41  537: 	}
1.4       harris41  538: 
1.2       harris41  539: 	if ($ENV{'form.openuri'}) {  # take care of review and refresh options
                    540: 	    my $uri=$ENV{'form.openuri'};
1.4       harris41  541: 	    if (exists($hash{'diropen_status_'.$uri})) {
                    542: 		my $cursta = $hash{'diropen_status_'.$uri};
1.2       harris41  543: 		$dirs{$uri} = 'open';
1.4       harris41  544: 		$hash{'diropen_status_'.$uri} = 'open';
                    545: 		if ($cursta eq 'open') {
                    546: 		    $dirs{$uri} = 'closed';
                    547: 		    $hash{'diropen_status_'.$uri} = 'closed';
                    548: 		}
1.2       harris41  549: 	    } else {
1.4       harris41  550: 		$hash{'diropen_status_'.$uri} = 'open';
1.2       harris41  551: 		$dirs{$uri} = 'open';
                    552: 	    }
                    553: 	}
1.12      ng        554: 	
                    555: 	my $toplevel;
1.13      ng        556: 	my $indent = 0;
1.12      ng        557: 	$uri = $uri.'/' if $uri !~ /.*\/$/;
1.17      harris41  558: 
1.88      www       559:  	if ($ENV{'form.dirPointer'} ne 'on') {
                    560:  	    $hash{'top.level'} = $uri;
                    561:  	    $toplevel = $uri;
                    562:  	} else {
                    563:  	    $toplevel = $hash{'top.level'};
                    564:  	}
1.17      harris41  565: 
1.23      harris41  566: # -------------------------------- if not at top level, provide an uplink arrow
1.45      ng        567: 	if ($toplevel ne '/res/'){
1.13      ng        568: 	    my (@uri_com) = split(/\//,$uri);
                    569: 	    pop @uri_com;
                    570: 	    my $upone = join('/',@uri_com);
                    571: 	    my @list = qw (0);
                    572: 	    &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
                    573: 	    $indent = 1;
1.12      ng        574: 	}
1.17      harris41  575: 
1.23      harris41  576: # -------- recursively go through all the directories and output as appropriate
1.16      harris41  577: 	&scanDir ($r,$toplevel,$indent,\%hash);
1.12      ng        578: 	
1.23      harris41  579: # ---------------------------- embed hidden information useful for group import
1.8       harris41  580: 	$r->print("<form name='fnum'>");
                    581: 	$r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
1.17      harris41  582: 
1.23      harris41  583: # -------------------------------------------------------------- end the tables
1.45      ng        584: 	$r->print('</table>');
                    585: 	$r->print('</td></tr></table>');
1.17      harris41  586: 
1.23      harris41  587: # --------------------------------------------------- end the output and return
1.45      ng        588: 	$r->print('</body></html>'."\n");
1.2       harris41  589:     }
1.67      matthew   590:     if(! $c->aborted()) {
1.87      www       591: # write back into the temporary file
1.68      albertel  592: 	my %dbfile;
1.67      matthew   593:         if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_NEWDB(),0640)) {
                    594:             while (my($key,$value) = each(%hash)) {
                    595:                 $dbfile{$key}=$value;
                    596:             }
                    597:             untie(%dbfile);
                    598:         }
                    599:     }
                    600: 
1.1       www       601:     return OK;
                    602: }
1.2       harris41  603: 
1.17      harris41  604: # ----------------------------------------------- recursive scan of a directory
1.2       harris41  605: sub scanDir {
1.16      harris41  606:     my ($r,$startdir,$indent,$hashref)=@_;
1.67      matthew   607:     my $c = $r->connection();
1.3       harris41  608:     my ($compuri,$curdir);
                    609:     my $dirptr=16384;
1.90      taceyjo1  610:     my $obs;
1.1       www       611:     $indent++;
1.2       harris41  612:     my %dupdirs = %dirs;
                    613:     my @list=&get_list($r,$startdir);
                    614:     foreach my $line (@list) {
1.67      matthew   615:         return if ($c->aborted());
1.90      taceyjo1  616: 	#This is a kludge, sorry aboot this
1.92      taceyjo1  617: 	my ($strip,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
1.90      taceyjo1  618: 	next if($strip =~ /.*\.meta$/ | $obs eq '1');
1.18      ng        619: 	my (@fileparts) = split(/\./,$strip);
1.70      ng        620: 	if ($hash{'display_attrs_9'} != 1) {
1.95      www       621: # if not all versions to be shown
1.18      ng        622: 	    if (scalar(@fileparts) >= 3) {
                    623: 		my $fext = pop @fileparts;
                    624: 		my $ov = pop @fileparts;
                    625: 		my $fname = join ('.',@fileparts,$fext);
1.75      albertel  626: 		next if (grep /\Q$fname\E/,@list and $ov =~ /^\d+$/);
1.18      ng        627: 	    }
                    628: 	}
                    629: 
1.45      ng        630: 	if ($dom eq 'domain') {
1.72      albertel  631: 	    # dom list has full path /res/<domain name>/ already
                    632: 	    $curdir='';
1.73      albertel  633: 	    $compuri = (split(/\&/,$line))[0];
1.2       harris41  634: 	} else {
1.17      harris41  635: 	    # user, dir & file have name only, i.e., w/o path
1.45      ng        636: 	    $compuri = join('',$startdir,$strip,'/');
1.3       harris41  637: 	    $curdir = $startdir;
1.2       harris41  638: 	}
1.45      ng        639: 	my $diropen = 'closed';
1.96      www       640: 	if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/) or ($compuri=~/\.(sequence|page)\/$/)) {
1.3       harris41  641: 	    while (my ($key,$val)= each %dupdirs) {
1.5       harris41  642: 		if ($key eq $compuri and $val eq "open") {
1.11      ng        643: 		    $diropen = "opened";
1.53      albertel  644: 		    delete($dupdirs{$key});
                    645: 		    delete($dirs{$key});
1.5       harris41  646: 		}
1.3       harris41  647: 	    }
1.1       www       648: 	}
1.16      harris41  649: 	&display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
1.45      ng        650: 	&scanDir ($r,$compuri,$indent) if $diropen eq 'opened';
1.1       www       651:     }
                    652:     $indent--;
                    653: }
                    654: 
1.17      harris41  655: # --------------- get complete matched list based on the uri (returns an array)
1.1       www       656: sub get_list {
                    657:     my ($r,$uri)=@_;
1.97      www       658:     my @list=();
1.45      ng        659:     (my $luri = $uri) =~ s/\//_/g;
1.87      www       660:     if ($ENV{'form.updatedisplay'}) {
1.27      harris41  661: 	foreach (keys %hash) {
1.4       harris41  662: 	    delete $hash{$_} if ($_ =~ /^dirlist_files_/);
1.87      www       663: 	}
1.2       harris41  664:     }
                    665: 
1.87      www       666:     if ($hash{'dirlist_files_'.$luri}) {
1.4       harris41  667: 	@list = split(/\n/,$hash{'dirlist_files_'.$luri});
1.97      www       668:     } elsif ($uri=~/\.(page|sequence)\/$/) {
1.94      www       669: # is a page or a sequence
1.97      www       670: 	$uri=~s/\/$//;
                    671: 	$uri='/'.(split(/\.(page|sequence)\/\//,$uri))[-1];
                    672: 	$uri=~s/\/+/\//g;
                    673: 	foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$uri))) {
                    674: 	    my @ratpart=split(/\:/,$_);
                    675: 	    push @list,$ratpart[1];
                    676: 	} 
1.94      www       677: 	$hash{'dirlist_files_'.$luri} = join("\n",@list);
1.1       www       678:     } else {
1.94      www       679: # is really a directory
1.4       harris41  680: 	@list = &Apache::lonnet::dirlist($uri);
1.87      www       681: 	$hash{'dirlist_files_'.$luri} = join("\n",@list);
1.112     www       682: 	&dynmetaread($uri);
1.1       www       683:     }
1.91      taceyjo1  684:     return @list=&match_ext($r,@list);
1.1       www       685: }
                    686: 
1.112     www       687: sub dynmetaread {
                    688:     my $uri=shift;
                    689:     if (($hash{'display_attrs_8'}==1) || ($hash{'display_attrs_11'}==1)) {
                    690: 	%dynhash=
                    691: 	    (%dynhash,&Apache::lonmeta::get_dynamic_metadata_from_sql($uri));
                    692:     } 
                    693: }
                    694: 
1.40      matthew   695: sub initdebug {
                    696:     return <<ENDJS;
                    697: <script>
                    698: var debugging = true;
                    699: if (debugging) {
                    700:     var debuggingWindow = window.open('','Debug','width=400,height=300',true);
                    701: } 
                    702: 
                    703: function output(text) {
                    704:     if (debugging) {
                    705:         debuggingWindow.document.writeln(text);
                    706:     }
                    707: }
                    708: output("<html><head><title>Debugging Window</title></head><body><pre>");   
                    709: </script>
                    710: ENDJS
                    711: }
                    712: 
                    713: sub writedebug {
                    714:     my $text = shift;
                    715:     return "<script>output('$text');</script>";
                    716: }
                    717: 
1.17      harris41  718: # -------------------- filters out files based on extensions (returns an array)
1.1       www       719: sub match_ext {
                    720:     my ($r,@packlist)=@_;
                    721:     my @trimlist;
                    722:     my $nextline;
                    723:     my @fileext;
                    724:     my $dirptr=16384;
                    725: 
1.2       harris41  726:     foreach my $line (@packlist) {
                    727: 	chomp $line;
                    728: 	$line =~ s/^\/home\/httpd\/html//;
                    729: 	my @unpackline = split (/\&/,$line);
1.45      ng        730: 	next if ($unpackline[0] eq '.');
                    731: 	next if ($unpackline[0] eq '..');
1.2       harris41  732: 	my @filecom = split (/\./,$unpackline[0]);
                    733: 	my $fext = pop(@filecom);
1.96      www       734: 	my $fnptr = ($unpackline[3]&$dirptr) || ($fext=~/\.(page|sequence)$/);
1.2       harris41  735:  	if ($fnptr == 0 and $unpackline[3] ne "") {
1.28      harris41  736: 	    my $embstyle = &Apache::loncommon::fileembstyle($fext);
1.25      matthew   737:             push @trimlist,$line if (defined($embstyle) && 
1.32      harris41  738: 				     ($embstyle ne 'hdn' or $fext eq 'meta'));
1.1       www       739: 	} else {
1.2       harris41  740: 	    push @trimlist,$line;
1.1       www       741: 	}
                    742:     }
1.80      albertel  743:     @trimlist = sort {uc($a) cmp uc($b)} (@trimlist);
1.1       www       744:     return @trimlist;
                    745: }
                    746: 
1.17      harris41  747: # ------------------------------- displays one line in appropriate table format
1.23      harris41  748: sub display_line {
1.16      harris41  749:     my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
1.53      albertel  750:     my (@pathfn, $fndir);
1.97      www       751: # there could be relative paths (files actually belonging into this directory)
                    752: # or absolute paths (for example, from sequences)
                    753:     my $absolute;
                    754:     my $pathprefix;
1.107     albertel  755:     if ($line=~m|^/res/| && $startdir ne '') {
1.97      www       756: 	$absolute=1;
                    757: 	$pathprefix='';
                    758:     } else {
                    759: 	$absolute=0;
                    760: 	$pathprefix=$startdir;
                    761:     }
1.1       www       762:     my $dirptr=16384;
                    763:     my $fileclr="#ffffe6";
1.45      ng        764:     my $iconpath= $r->dir_config('lonIconsURL') . '/';
1.1       www       765: 
                    766:     my @filecom = split (/\&/,$line);
                    767:     my @pathcom = split (/\//,$filecom[0]);
                    768:     my $listname = $pathcom[scalar(@pathcom)-1];
                    769:     my $fnptr = $filecom[3]&$dirptr;
1.77      www       770:     my $msg = &mt('View').' '.$filecom[0].' '.&mt('resources');
                    771:     $msg = &mt('Close').' '.$filecom[0].' '.&mt('directory') if $diropen eq 'opened';
1.1       www       772: 
1.45      ng        773:     my $tabtag='</td>';
1.1       www       774:     my $i=0;
1.109     taceyjo1  775:     while ($i<=11) {
1.45      ng        776: 	$tabtag=join('',$tabtag,"<td>&nbsp;</td>")
1.17      harris41  777: 	    if $hash{'display_attrs_'.$i} == 1;
1.1       www       778: 	$i++;
                    779:     }
1.63      ng        780:     my $valign = ($hash{'display_attrs_7'} == 1 ? 'top' : 'bottom');
1.17      harris41  781: 
                    782: # display uplink arrow
1.45      ng        783:     if ($filecom[1] eq 'viewOneUp') {
1.98      www       784: 	my $updir=$startdir;
                    785: # -------------- Filter out sequence containment in crumbs and "recent folders"
                    786: 	$updir='/'.(split(/\.(page|sequence)\/\//,$startdir))[-1];
                    787: 	$updir=~s/\/+/\//g;
                    788: 
1.70      ng        789: 	$r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
                    790: 	$r->print("<td>\n");
1.98      www       791: 	$r->print ('<form method="post" name="dirpathUP" action="'.$updir.
1.16      harris41  792: 		   '/" '.
1.17      harris41  793: 		   'onSubmit="return rep_dirpath(\'UP\','.
                    794: 		   'document.forms.fileattr.acts.value)" '.
1.16      harris41  795: 		   'enctype="application/x-www-form-urlencoded"'.
                    796:                    '>'."\n");
1.17      harris41  797: 	$r->print ('<input type=hidden name=openuri value="'.
                    798: 		   $startdir.'">'."\n");
1.16      harris41  799: 	$r->print ('<input type="hidden" name="acts" value="">'."\n");
1.13      ng        800: 	$r->print ('<input src="'.$iconpath.'arrow_up.gif"');
1.17      harris41  801: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    802: 		   "\n");
1.77      www       803: 	$r->print(&mt("Up")." $tabtag</tr></form>\n");
1.13      ng        804: 	return OK;
                    805:     }
1.97      www       806: # Do we have permission to look at this?
                    807: 
                    808:     if($filecom[15] ne '1') { return OK if (!&Apache::lonnet::allowed('bre',$pathprefix.$filecom[0])); }
                    809: 
                    810: # make absolute links appear on different background
1.112     www       811:     if ($absolute) { $fileclr='#ccdd99'; }
1.17      harris41  812: 
                    813: # display domain
1.45      ng        814:     if ($filecom[1] eq 'domain') {
1.88      www       815:  	$r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
                    816:  	    if ($ENV{'form.dirPointer'} eq "on");
1.70      ng        817: 	$r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
                    818: 	$r->print("<td>");
1.73      albertel  819: 	&begin_form ($r,$filecom[0]);
                    820: 	my $anchor = $filecom[0];
1.3       harris41  821: 	$anchor =~ s/\///g;
1.13      ng        822: 	$r->print ('<a name="'.$anchor.'">');
1.16      harris41  823: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17      harris41  824: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.
                    825: 		   $diropen.'.gif"'); 
                    826: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    827: 		   "\n");
                    828: 	$r->print ('<a href="javascript:gothere(\''.$filecom[0].
1.73      albertel  829: 		   '\')"><img src="'.$iconpath.'server.gif"');
1.17      harris41  830: 	$r->print (' border="0" /></a>'."\n");
1.77      www       831: 	$r->print (&mt("Domain")." - $listname ");
1.60      albertel  832: 	if ($Apache::lonnet::domaindescription{$listname}) {
                    833: 	    $r->print("(".$Apache::lonnet::domaindescription{$listname}.
                    834: 		      ")");
                    835: 	}
                    836: 	$r->print (" $tabtag</tr></form>\n");
1.1       www       837: 	return OK;
1.17      harris41  838: 
                    839: # display user directory
1.1       www       840:     }
1.45      ng        841:     if ($filecom[1] eq 'user') {
1.70      ng        842: 	$r->print("<tr valign=$valign bgcolor=$fileclr>$extrafield");
                    843: 	$r->print("<td nowrap>\n");
1.2       harris41  844: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41  845: 	my $anchor = $curdir;
                    846: 	$anchor =~ s/\///g;
1.13      ng        847: 	&begin_form ($r,$curdir);
1.17      harris41  848: 	$r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
                    849: 		   'whitespace1.gif" border="0" />'."\n");
1.16      harris41  850: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17      harris41  851: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
                    852: 		   '.gif"'); 
                    853: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    854: 		   "\n");
                    855: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
                    856: 		   $iconpath.'quill.gif border="0" name="'.$msg.
                    857: 		   '" height="22" /></a>');
1.60      albertel  858: 	my $domain=(split(m|/|,$startdir))[2];
                    859: 	my $plainname=&Apache::loncommon::plainname($listname,$domain);
                    860: 	$r->print ($listname);
                    861: 	if (defined($plainname) && $plainname) { $r->print(" ($plainname) "); }
                    862: 	$r->print ($tabtag.'</tr></form>'."\n");
1.1       www       863: 	return OK;
                    864:     }
1.17      harris41  865: 
1.1       www       866: # display file
1.97      www       867:     if (($fnptr == 0 and $filecom[3] ne '') or $absolute) {
                    868: 	my $filelink = $pathprefix.$filecom[0];
1.1       www       869: 	my @file_ext = split (/\./,$listname);
1.25      matthew   870: 	my $curfext = $file_ext[-1];
1.40      matthew   871:         if (@Omit) {
                    872:             foreach (@Omit) { return OK if ($curfext eq $_); }
                    873:         }
                    874:         if (@Only) {
                    875:             my $skip = 1;
                    876:             foreach (@Only) { $skip = 0 if ($curfext eq $_); }
                    877:             return OK if ($skip > 0);
                    878:         }
1.25      matthew   879: 	# Set the icon for the file
1.84      albertel  880: 	my $iconname = &Apache::loncommon::icon($listname);
1.114     www       881: 	$r->print("<tr valign='$valign' bgcolor=$fileclr><td nowrap='1' align='top'>");
1.104     albertel  882: 	
                    883: 	my $metafile = $Apache::lonnet::perlvar{'lonDocRoot'}.$pathprefix.
                    884: 	    $filecom[0].'.meta';
                    885: 	if (-e $metafile) {
                    886: 	    $metafile=1;
                    887: 	} else {
                    888: 	    $metafile=0;
                    889: 	}
1.7       harris41  890:         if ($ENV{'form.catalogmode'} eq 'interactive') {
1.35      matthew   891:             $r->print("<a href=\"javascript:select_data(\'",
1.108     albertel  892:                       $filelink,"')\">");
1.17      harris41  893: 	    $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
                    894: 		      "\n");
1.70      ng        895: 	    $r->print("</td><td nowrap>");
1.95      www       896: 	} elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
1.8       harris41  897: 	    $r->print("<form name='form$fnum'>\n");
                    898: 	    $r->print("<input type='checkbox' name='filelink"."' ".
1.16      harris41  899: 		      "value='$filelink' onClick='".
                    900: 		      "javascript:queue(\"form$fnum\")' ");
                    901: 	    if ($hash{'store_'.$filelink}) {
                    902: 		$r->print("checked");
                    903: 	    }
                    904: 	    $r->print(">\n");
1.8       harris41  905: 	    $r->print("</form>\n");
1.70      ng        906: 	    $r->print("</td><td nowrap>");
1.16      harris41  907: 	    $hash{"pre_${fnum}_link"}=$filelink;
1.8       harris41  908:   	    $fnum++;
1.7       harris41  909: 	}
1.95      www       910: # Form to open or close sequences
                    911: 	if ($filelink=~/\.(page|sequence)$/) {
                    912: 	    my $curdir = $startdir.$filecom[0].'/';
                    913: 	    my $anchor = $curdir;
                    914: 	    $anchor =~ s/\///g;
                    915: 	    &begin_form($r,$curdir);
                    916: 	    $indent--;
                    917: 	}
                    918: # General indentation
1.12      ng        919: 	if ($indent > 0 and $indent < 11) {
1.17      harris41  920: 	    $r->print("<img src=",$iconpath,"whitespace",$indent,
                    921: 		      ".gif border='0' />\n");
1.11      ng        922: 	} elsif ($indent >0) {
1.4       harris41  923: 	    my $ten = int($indent/10.);
                    924: 	    my $rem = $indent%10.0;
                    925: 	    my $count = 0;
                    926: 	    while ($count < $ten) {
1.17      harris41  927: 		$r->print("<img src=",$iconpath,
                    928: 			  "whitespace10.gif border='0' />\n");
1.1       www       929: 	    $count++;
1.4       harris41  930: 	    }
1.17      harris41  931: 	    $r->print("<img src=",$iconpath,"whitespace",$rem,
                    932: 		      ".gif border='0' />\n") if $rem > 0;
1.1       www       933: 	}
1.95      www       934: # Sequence open/close icon
                    935: 	if ($filelink=~/\.(page|sequence)$/) {
                    936: 	    my $curdir = $startdir.$filecom[0].'/';
                    937: 	    my $anchor = $curdir;
                    938: 	    $anchor =~ s/\///g;
                    939: 	    $r->print ('<input type="hidden" name="acts" value="">');
                    940: 	    $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
                    941: 		       'folder_pointer_'.$diropen.'.gif"');
                    942: 	    $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    943: 		       "\n");
                    944: 	}
                    945: # Filetype icons
1.84      albertel  946: 	$r->print("<img src='$iconname' border='0' />\n");
1.95      www       947: # Close form to open/close sequence
                    948: 	if ($filelink=~/\.(page|sequence)$/) {
                    949: 	    $r->print('</form>');
                    950: 	}
1.17      harris41  951: 	$r->print (" <a href=\"javascript:openWindow('".$filelink.
1.69      www       952: 		   "', 'previewfile', '450', '500', 'no', 'yes','yes')\";".
1.17      harris41  953: 		   " TARGET=_self>$listname</a> ");
                    954: 
                    955: 	$r->print (" (<a href=\"javascript:openWindow('".$filelink.
1.71      ng        956: 		   ".meta', 'metadatafile', '500', '550', 'no', 'yes','no')\"; ".
1.104     albertel  957: 		   "TARGET=_self>metadata</a>) ");
1.7       harris41  958: 	$r->print("</td>\n");
1.45      ng        959: 	if ($hash{'display_attrs_0'} == 1) {
1.104     albertel  960: 	    my $title = &Apache::lonnet::gettitle($filelink,'title');
1.70      ng        961: 	    $r->print('<td> '.($title eq '' ? '&nbsp;' : $title).
1.45      ng        962: 		      ' </td>'."\n");
                    963: 	}
1.70      ng        964: 	$r->print('<td align=right> ',
1.17      harris41  965: 		  $filecom[8]," </td>\n") 
1.45      ng        966: 	    if $hash{'display_attrs_1'} == 1;
1.70      ng        967: 	$r->print('<td> '.
1.17      harris41  968: 		  (localtime($filecom[9]))." </td>\n") 
1.45      ng        969: 	    if $hash{'display_attrs_2'} == 1;
1.70      ng        970: 	$r->print('<td> '.
1.17      harris41  971: 		  (localtime($filecom[10]))." </td>\n") 
1.45      ng        972: 	    if $hash{'display_attrs_3'} == 1;
1.2       harris41  973: 
1.45      ng        974: 	if ($hash{'display_attrs_4'} == 1) {
1.104     albertel  975: 	    my $author = &Apache::lonnet::metadata($filelink,'author');
1.70      ng        976: 	    $r->print('<td> '.($author eq '' ? '&nbsp;' : $author).
1.17      harris41  977: 		      " </td>\n");
1.2       harris41  978: 	}
1.45      ng        979: 	if ($hash{'display_attrs_5'} == 1) {
1.104     albertel  980: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
1.45      ng        981: 	    # $keywords = '&nbsp;' if (!$keywords);
1.70      ng        982: 	    $r->print('<td> '.($keywords eq '' ? '&nbsp;' : $keywords).
1.17      harris41  983: 		      " </td>\n");
1.2       harris41  984: 	}
1.109     taceyjo1  985: #'
                    986: 
1.45      ng        987: 	if ($hash{'display_attrs_6'} == 1) {
1.104     albertel  988: 	    my $lang = &Apache::lonnet::metadata($filelink,'language');
1.28      harris41  989: 	    $lang = &Apache::loncommon::languagedescription($lang);
1.70      ng        990: 	    $r->print('<td> '.($lang eq '' ? '&nbsp;' : $lang).
1.17      harris41  991: 		      " </td>\n");
1.2       harris41  992: 	}
1.70      ng        993: 	if ($hash{'display_attrs_8'} == 1) {
1.111     www       994: # statistics
1.112     www       995: 	    $r->print("<td>");
1.114     www       996: 	    &dynmetaprint($r,$filelink,'count');
                    997: 	    &dynmetaprint($r,$filelink,'course');
                    998: 	    &dynmetaprint($r,$filelink,'stdno');
                    999: 	    &dynmetaprint($r,$filelink,'avetries');
                   1000: 	    &dynmetaprint($r,$filelink,'difficulty');
                   1001: 	    &dynmetaprint($r,$filelink,'disc');
                   1002: 	    &dynmetaprint($r,$filelink,'clear');
                   1003: 	    &dynmetaprint($r,$filelink,'technical');
                   1004: 	    &dynmetaprint($r,$filelink,'correct');
                   1005: 	    &dynmetaprint($r,$filelink,'helpful');
                   1006: 	    &dynmetaprint($r,$filelink,'depth');
1.112     www      1007: 	    $r->print("&nbsp;</td>\n");
1.111     www      1008: 
1.70      ng       1009: 	}
1.109     taceyjo1 1010: 	if ($hash{'display_attrs_10'} == 1) {
                   1011: 	    my $source = &Apache::lonnet::metadata($filelink,'sourceavail');
1.110     albertel 1012: 	    if($source eq 'open') {
                   1013: 		my $sourcelink = &Apache::lonsource::make_link($filelink);
                   1014: 		$r->print('<td>'."<a href=\"javascript:openWindow('".$sourcelink.
                   1015: 			  "', 'previewsource', '700', '700', 'no', 'yes','yes')\";".
                   1016: 			  " TARGET=_self>Yes</a> "."</td>\n");
                   1017: 	    } else { #A cuddled else. :P
1.111     www      1018: 		$r->print("<td>&nbsp;</td>\n");
1.110     albertel 1019: 	    }
1.109     taceyjo1 1020: 	}
1.111     www      1021: 	if ($hash{'display_attrs_11'} == 1) {
                   1022: # links
1.113     www      1023: 	   $r->print('<td>');
                   1024: 	   &dynmetaprint($r,$filelink,'goto_list');
                   1025: 	   &dynmetaprint($r,$filelink,'comefrom_list');
                   1026: 	   &dynmetaprint($r,$filelink,'sequsage_list');
1.114     www      1027: 	   &dynmetaprint($r,$filelink,'dependencies');
1.113     www      1028: 	   $r->print('</td>');
1.114     www      1029:         }
1.115   ! www      1030:         if ($hash{'display_attrs_7'} == 1) {
        !          1031: # Show resource
        !          1032:             my $output='';
        !          1033:             my $embstyle=&Apache::loncommon::fileembstyle($curfext);
        !          1034: 	    if ($embstyle eq 'ssi') {
        !          1035: 		my $cache=$Apache::lonnet::perlvar{'lonDocRoot'}.$filelink.
        !          1036: 		    '.tmp';
        !          1037: 		if ((!$ENV{'form.updatedisplay'}) &&
        !          1038: 		    (-e $cache)) {
        !          1039: 		    open(FH,$cache);
        !          1040: 		    $output=join("\n",<FH>);
        !          1041: 		    close(FH);
        !          1042: 		} else {
        !          1043: 		    $output=&Apache::lonnet::ssi_body($filelink);
        !          1044: 		    open(FH,">$cache");
        !          1045: 		    print FH $output;
        !          1046: 		    close(FH);
        !          1047: 		}
        !          1048: 		$output='<font size="-2">'.$output.'</font>';
        !          1049: 	   } elsif ($embstyle eq 'img') {
        !          1050:                $output='<img src="'.$filelink.'" />';
        !          1051:            } elsif ($filelink=~/^\/res\/(\w+)\/(\w+)\//) {
        !          1052:                $output='<img src="http://'.
        !          1053: 		 $Apache::lonnet::hostname{&Apache::lonnet::homeserver($2,$1)}.
        !          1054:                  '/cgi-bin/thumbnail.gif?url='.$filelink.'" />';
        !          1055:            }
        !          1056: 	   $r->print('<td> '.($output eq '' ? '&nbsp;':$output).
        !          1057: 		      " </td>\n");
        !          1058:         }
1.1       www      1059: 	$r->print("</tr>\n");
                   1060:     }
1.17      harris41 1061: 
1.2       harris41 1062: # -- display directory
1.1       www      1063:     if ($fnptr == $dirptr) {
1.2       harris41 1064: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41 1065: 	my $anchor = $curdir;
                   1066: 	$anchor =~ s/\///g;
1.63      ng       1067: 	$r->print("<tr bgcolor=$fileclr>$extrafield<td valign=$valign>");
1.2       harris41 1068: 	&begin_form ($r,$curdir);
1.4       harris41 1069: 	my $indentm1 = $indent-1;
1.11      ng       1070: 	if ($indentm1 < 11 and $indentm1 > 0) {
1.17      harris41 1071: 	    $r->print("<img src=",$iconpath,"whitespace",$indentm1,
                   1072: 		      ".gif border='0' />\n");
1.4       harris41 1073: 	} else {
                   1074: 	    my $ten = int($indentm1/10.);
                   1075: 	    my $rem = $indentm1%10.0;
                   1076: 	    my $count = 0;
                   1077: 	    while ($count < $ten) {
1.17      harris41 1078: 		$r->print ("<img src=",$iconpath
                   1079: 			   ,"whitespace10.gif border='0' />\n");
1.12      ng       1080: 		$count++;
1.4       harris41 1081: 	    }
1.17      harris41 1082: 	    $r->print ("<img src=",$iconpath,"whitespace",$rem,
                   1083: 		       ".gif border='0' />\n") if $rem > 0;
1.1       www      1084: 	}
1.16      harris41 1085: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17      harris41 1086: 	$r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
                   1087: 		   'folder_pointer_'.$diropen.'.gif"');
                   1088: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                   1089: 		   "\n");
                   1090: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
                   1091: 		   $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
                   1092: 		   "\n");
1.86      www      1093: 	$r->print ("$listname</td>\n");
                   1094: # Attributes
                   1095: 	my $filelink = $startdir.$filecom[0].'/default';
                   1096: 
                   1097: 	if ($hash{'display_attrs_0'} == 1) {
                   1098: 	    my $title = &Apache::lonnet::gettitle($filelink,'title');
                   1099: 	    $r->print('<td> '.($title eq '' ? '&nbsp;' : $title).
                   1100: 		      ' </td>'."\n");
                   1101: 	}
                   1102: 	$r->print('<td align=right> ',
                   1103: 		  $filecom[8]," </td>\n") 
                   1104: 	    if $hash{'display_attrs_1'} == 1;
                   1105: 	$r->print('<td> '.
                   1106: 		  (localtime($filecom[9]))." </td>\n") 
                   1107: 	    if $hash{'display_attrs_2'} == 1;
                   1108: 	$r->print('<td> '.
                   1109: 		  (localtime($filecom[10]))." </td>\n") 
                   1110: 	    if $hash{'display_attrs_3'} == 1;
                   1111: 
                   1112: 	if ($hash{'display_attrs_4'} == 1) {
                   1113: 	    my $author = &Apache::lonnet::metadata($filelink,'author');
                   1114: 	    $r->print('<td> '.($author eq '' ? '&nbsp;' : $author).
                   1115: 		      " </td>\n");
                   1116: 	}
                   1117: 	if ($hash{'display_attrs_5'} == 1) {
                   1118: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
                   1119: 	    # $keywords = '&nbsp;' if (!$keywords);
                   1120: 	    $r->print('<td> '.($keywords eq '' ? '&nbsp;' : $keywords).
                   1121: 		      " </td>\n");
                   1122: 	}
                   1123: 	if ($hash{'display_attrs_6'} == 1) {
                   1124: 	    my $lang = &Apache::lonnet::metadata($filelink,'language');
                   1125: 	    $lang = &Apache::loncommon::languagedescription($lang);
                   1126: 	    $r->print('<td> '.($lang eq '' ? '&nbsp;' : $lang).
                   1127: 		      " </td>\n");
                   1128: 	}
                   1129: 	if ($hash{'display_attrs_8'} == 1) {
                   1130: 	   $r->print('<td>&nbsp;</td>');
                   1131: 	}
1.115   ! www      1132:  	if ($hash{'display_attrs_10'} == 1) {
1.109     taceyjo1 1133: 	   $r->print('<td>&nbsp;</td>');
                   1134: 	}
1.111     www      1135: 	if ($hash{'display_attrs_11'} == 1) {
                   1136: 	   $r->print('<td>&nbsp;</td>');
                   1137: 	}
1.115   ! www      1138: 	if ($hash{'display_attrs_7'} == 1) {
        !          1139: 	   $r->print('<td>&nbsp;</td>');
        !          1140:         }
1.86      www      1141: 	$r->print('</form></tr>');
1.1       www      1142:     }
1.2       harris41 1143: 
1.1       www      1144: }
                   1145: 
1.113     www      1146: sub dynmetaprint {
                   1147:     my ($r,$filelink,$item)=@_;
                   1148:     if ($dynhash{$filelink}->{$item}) {
1.114     www      1149: 	$r->print("\n<br />".$fieldnames{$item}.': '.
1.113     www      1150: 		  &Apache::lonmeta::prettyprint($item,
                   1151: 						$dynhash{$filelink}->{$item},
                   1152: 		  (($ENV{'form.catalogmode'} ne 'groupimport')?'preview':''),
                   1153: 		  '',
                   1154: 		  (($ENV{'form.catalogmode'} eq 'groupimport')?'document.forms.fileattr':''),1));
                   1155:     }
                   1156: }
                   1157: 
1.14      harris41 1158: # ------------------- prints the beginning of a form for directory or file link
1.1       www      1159: sub begin_form {
                   1160:     my ($r,$uri) = @_;
1.3       harris41 1161:     my $anchor = $uri;
                   1162:     $anchor =~ s/\///g;
1.17      harris41 1163:     $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
                   1164: 	       '#'.$anchor.
                   1165: 	       '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
                   1166: 	       ',document.forms.fileattr.acts.value)" '.
1.16      harris41 1167: 	       'enctype="application/x-www-form-urlencoded">'."\n");
1.17      harris41 1168:     $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
                   1169: 	       "\n");
1.88      www      1170:     $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
1.16      harris41 1171:     $dnum++;
1.17      harris41 1172: }
                   1173: 
                   1174: # --------- settings whenever the user causes the indexer window to be launched
                   1175: sub start_fresh_session {
1.48      matthew  1176:     delete $hash{'form.catalogmode'};
                   1177:     delete $hash{'form.mode'};
                   1178:     delete $hash{'form.form'};
                   1179:     delete $hash{'form.element'};
                   1180:     delete $hash{'form.omit'};
                   1181:     delete $hash{'form.only'};
1.27      harris41 1182:     foreach (keys %hash) {
1.48      matthew  1183:         delete $hash{$_} if (/^(pre_|store)/);
1.27      harris41 1184:     }
1.1       www      1185: }
                   1186: 
1.35      matthew  1187: # ------------------------------------------------------------------- setvalues
                   1188: sub setvalues {
                   1189:     # setvalues is used in registerurl to synchronize the database
                   1190:     # hash and environment hashes
                   1191:     my ($H1,$h1key,$H2,$h2key) =@_;
                   1192:     #
                   1193:     if (exists $H2->{$h2key}) {
                   1194: 	$H1->{$h1key} = $H2->{$h2key};
                   1195:     } elsif (exists $H1->{$h1key}) {
                   1196: 	$H2->{$h2key} = $H1->{$h1key};
                   1197:     } 
                   1198: }
                   1199: 
1.1       www      1200: 1;
1.54      www      1201: 
                   1202: sub cleanup {
1.55      www      1203:     if (tied(%hash)){
                   1204: 	&Apache::lonnet::logthis('Cleanup indexer: hash');
                   1205:     }
1.54      www      1206: }
1.23      harris41 1207: 
                   1208: =head1 NAME
                   1209: 
                   1210: Apache::lonindexer - mod_perl module for cross server filesystem browsing
                   1211: 
                   1212: =head1 SYNOPSIS
                   1213: 
                   1214: Invoked by /etc/httpd/conf/srm.conf:
                   1215: 
                   1216:  <LocationMatch "^/res.*/$">
                   1217:  SetHandler perl-script
                   1218:  PerlHandler Apache::lonindexer
                   1219:  </LocationMatch>
                   1220: 
                   1221: =head1 INTRODUCTION
                   1222: 
                   1223: This module enables a scheme of browsing across a cross server.
                   1224: 
                   1225: This is part of the LearningOnline Network with CAPA project
                   1226: described at http://www.lon-capa.org.
                   1227: 
                   1228: =head1 BEGIN SUBROUTINE
                   1229: 
                   1230: This routine is only run once after compilation.
                   1231: 
                   1232: =over 4
                   1233: 
                   1234: =item *
                   1235: 
                   1236: Initializes %language hash table.
                   1237: 
                   1238: =back
                   1239: 
                   1240: =head1 HANDLER SUBROUTINE
                   1241: 
                   1242: This routine is called by Apache and mod_perl.
                   1243: 
                   1244: =over 4
                   1245: 
                   1246: =item *
                   1247: 
                   1248: read in machine configuration variables
                   1249: 
                   1250: =item *
                   1251: 
                   1252: see if called from an interactive mode
                   1253: 
                   1254: =item *
                   1255: 
                   1256: refresh environment with user database values (in %hash)
                   1257: 
                   1258: =item *
                   1259: 
                   1260: define extra fields and buttons in case of special mode
                   1261: 
                   1262: =item *
                   1263: 
                   1264: set catalogmodefunctions to have extra needed javascript functionality
                   1265: 
                   1266: =item *
                   1267: 
                   1268: print header
                   1269: 
                   1270: =item *
                   1271: 
                   1272: evaluate actions from previous page (both cumulatively and chronologically)
                   1273: 
                   1274: =item *
                   1275: 
                   1276: output title
                   1277: 
                   1278: =item *
                   1279: 
                   1280: get state of file attributes to be showing
                   1281: 
                   1282: =item *
                   1283: 
                   1284: output state of file attributes to be showing
                   1285: 
                   1286: =item *
                   1287: 
                   1288: output starting row to the indexed file/directory hierarchy
                   1289: 
                   1290: =item *
                   1291: 
                   1292: read in what directories have previously been set to "open"
                   1293: 
                   1294: =item *
                   1295: 
                   1296: if not at top level, provide an uplink arrow
                   1297: 
                   1298: =item *
                   1299: 
                   1300: recursively go through all the directories and output as appropriate
                   1301: 
                   1302: =item *
                   1303: 
                   1304: information useful for group import
                   1305: 
                   1306: =item *
                   1307: 
                   1308: end the tables
                   1309: 
                   1310: =item *
                   1311: 
                   1312: end the output and return
                   1313: 
                   1314: =back
                   1315: 
                   1316: =head1 OTHER SUBROUTINES
                   1317: 
                   1318: =over 4
                   1319: 
                   1320: =item *
                   1321: 
                   1322: scanDir - recursive scan of a directory
                   1323: 
                   1324: =item *
                   1325: 
                   1326: get_list - get complete matched list based on the uri (returns an array)
                   1327: 
                   1328: =item *
                   1329: 
                   1330: match_ext - filters out files based on extensions (returns an array)
                   1331: 
                   1332: =item *
                   1333: 
                   1334: display_line - displays one line in appropriate table format
                   1335: 
                   1336: =item *
                   1337: 
                   1338: begin_form - prints the beginning of a form for directory or file link
                   1339: 
                   1340: =item *
                   1341: 
                   1342: start_fresh_session - settings whenever the user causes the indexer window
                   1343: to be launched
                   1344: 
                   1345: =back
                   1346: 
                   1347: =cut

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