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

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

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