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

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

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