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

1.1       www         1: # The LearningOnline Network with CAPA
1.24      harris41    2: # Directory Indexer
                      3: #
1.230   ! raeburn     4: # $Id: lonindexer.pm,v 1.229 2018/08/09 13:52:07 raeburn 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)       ##
1.217     raeburn    37: ## 4. Handling routine called via Apache and mod_perl                        ##
                     38: ## 5. Other subroutines                                                      ##
1.23      harris41   39: ##                                                                           ##
                     40: ###############################################################################
1.7       harris41   41: 
1.1       www        42: package Apache::lonindexer;
                     43: 
1.23      harris41   44: # ------------------------------------------------- modules used by this module
1.1       www        45: use strict;
1.133     albertel   46: use Apache::lonnet;
1.30      harris41   47: use Apache::loncommon();
1.83      www        48: use Apache::lonhtmlcommon();
1.94      www        49: use Apache::lonsequence();
1.1       www        50: use Apache::Constants qw(:common);
1.70      ng         51: use Apache::lonmeta;
1.2       harris41   52: use Apache::File;
1.77      www        53: use Apache::lonlocal;
1.109     taceyjo1   54: use Apache::lonsource();
1.172     albertel   55: use Apache::groupsort();
1.2       harris41   56: use GDBM_File;
1.154     albertel   57: use LONCAPA qw(:match);
1.2       harris41   58: 
1.23      harris41   59: # ---------------------------------------- variables used throughout the module
1.87      www        60: my %hash; # global user-specific gdbm file
1.17      harris41   61: my %dirs; # keys are directories, values are the open/close status
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.125     foxr       76: 
                     77: 
1.23      harris41   78: # ----------------------------- Handling routine called via Apache and mod_perl
1.1       www        79: sub handler {
                     80:     my $r = shift;
1.67      matthew    81:     my $c = $r->connection();
1.76      www        82:     &Apache::loncommon::content_type($r,'text/html');
1.50      albertel   83:     &Apache::loncommon::no_cache($r);
1.1       www        84:     $r->send_http_header;
                     85:     return OK if $r->header_only;
1.9       harris41   86:     $fnum=0;
1.16      harris41   87:     $dnum=0;
1.17      harris41   88: 
1.43      matthew    89:     # Deal with stupid global variables (is there a way around making
                     90:     # these global to this package?  It is just so wrong....)
                     91:     undef (@Only);
                     92:     undef (@Omit);
1.113     www        93:     %fieldnames=&Apache::lonmeta::fieldnames();
1.43      matthew    94: 
1.220     raeburn    95: # --------------------------------------------------------------- get icon path
1.10      harris41   96:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.227     raeburn    97:     my $defdom = &Apache::lonnet::default_login_domain();
1.1       www        98: 
1.182     bisitz     99: #SB my $fileclr='#ffffe6';
1.15      harris41  100:     my $line;
1.176     banghart  101:     my (@attrchk,@openpath,$typeselect);
1.15      harris41  102:     my $uri=$r->uri;
                    103: 
1.7       harris41  104: # -------------------------------------- see if called from an interactive mode
1.35      matthew   105:     # Get the parameters from the query string
1.36      matthew   106:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.40      matthew   107: 	     ['catalogmode','launch','acts','mode','form','element',
1.79      albertel  108:               'only','omit','titleelement']);
1.35      matthew   109:     #-------------------------------------------------------------------
1.17      harris41  110:     my $closebutton='';
1.7       harris41  111:     my $groupimportbutton='';
                    112:     my $colspan=''; 
1.141     albertel  113:     
1.14      harris41  114:     $extrafield='';
1.209     foxr      115:     my $diropendb = LONCAPA::tempdir() .
                    116: 	"$env{'user.domain'}_$env{'user.name'}_sel_res.db";
1.67      matthew   117:     %hash = ();
1.68      albertel  118:     {
                    119: 	my %dbfile;
1.149     albertel  120: 	if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_WRITER(),0640)) {
                    121: 	    if ($env{'form.launch'} eq '1') {
                    122: 		&start_fresh_session(\%dbfile);
                    123: 	    }
1.68      albertel  124: 	    while(my($key,$value)=each(%dbfile)) {
                    125: 		$hash{$key}=$value;
                    126: 	    }
                    127: 	    untie(%dbfile);
                    128: 	}
                    129:     }
1.174     banghart  130: # - Evaluate actions from previous page (both cumulatively and chronologically)
                    131:         if ($env{'form.catalogmode'} eq 'import' || $hash{'form.catalogmode'} eq 'import') {
                    132: 	    &Apache::groupsort::update_actions_hash(\%hash);
                    133: 	}
                    134:     
1.68      albertel  135:     {
1.105     taceyjo1  136:   #Hijack lonindexer to verify a title and be close down.
1.133     albertel  137:    if ($env{'form.launch'} eq '2') {
1.130     albertel  138:        &Apache::loncommon::content_type($r,'text/html');
1.108     albertel  139:        my $extra='';
1.133     albertel  140:        if (defined($env{'form.titleelement'}) && 
                    141: 	   $env{'form.titleelement'} ne '') {
                    142: 	   my $verify_title = &Apache::lonnet::gettitle($env{'form.acts'});
                    143: #	   &Apache::lonnet::logthis("Hrrm $env{'form.acts'} -- $verify_title");
1.108     albertel  144: 	   $verify_title=~s/'/\\'/g;
1.133     albertel  145: 	   $extra='window.opener.document.forms["'.$env{'form.form'}.'"].elements["'.$env{'form.titleelement'}.'"].value=\''.$verify_title.'\';';
1.108     albertel  146:        }
1.141     albertel  147:        my $js = <<ENDSUBM;
1.129     albertel  148: 	       <script type="text/javascript">
1.105     taceyjo1  149: 		function load() {
1.133     albertel  150: 			window.opener.document.forms["$env{'form.form'}"]
                    151: 			    .elements["$env{'form.element'}"]
                    152: 			    .value='$env{'form.acts'}';
1.108     albertel  153: 			$extra
1.105     taceyjo1  154: 			window.close();
                    155: 		}
1.129     albertel  156:    	       </script>
1.105     taceyjo1  157: ENDSUBM
1.141     albertel  158:        $r->print(&Apache::loncommon::start_page(undef,$js,
                    159: 						{'only_body'   =>1,
1.213     www       160:                                                  'add_modal' => 1,
                    161:                                                  'add_wishlist' => 1,
1.141     albertel  162: 						 'add_entries' =>
1.142     albertel  163: 						     {'onload' => "load();"},}
                    164: 						).
1.141     albertel  165: 		 &Apache::loncommon::end_page());
1.108     albertel  166:        return OK;
1.105     taceyjo1  167:    }
                    168:     
1.17      harris41  169: # -------------------- refresh environment with user database values (in %hash)
1.133     albertel  170: 	&setvalues(\%hash,'form.catalogmode',\%env,'form.catalogmode'   );
1.15      harris41  171: 
1.17      harris41  172: # --------------------- define extra fields and buttons in case of special mode
1.133     albertel  173: 	if ($env{'form.catalogmode'} eq 'interactive') {
1.182     bisitz    174: #SB	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
1.194     jms       175:             $extrafield='<td class="LC_bottom">'.
1.152     albertel  176: 		'<img alt="" src="'.$iconpath.'whitespace1.gif"'.
1.162     albertel  177: 		' class="LC_icon" /></td>';
1.15      harris41  178: 	    $colspan=" colspan='2' ";
1.77      www       179:             my $cl=&mt('Close');
1.15      harris41  180:             $closebutton=<<END;
1.199     droeschl  181: <input type="button" name="close" value='$cl' onclick="self.close()" />
1.7       harris41  182: END
1.16      harris41  183:         }
1.145     www       184: 	elsif ($env{'form.catalogmode'} eq 'import') {
1.182     bisitz    185: #SB	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
1.194     jms       186:             $extrafield='<td class="LC_bottom">'.
1.152     albertel  187: 		'<img alt="" src="'.$iconpath.'whitespace1.gif"'.
1.162     albertel  188: 		' class="LC_icon" /></td>';
1.15      harris41  189: 	    $colspan=" colspan='2' ";
1.77      www       190: 	    my $cl=&mt('Close');
1.123     matthew   191:             my $gi=&mt('Import');
1.15      harris41  192:             $closebutton=<<END;
1.199     droeschl  193: <input type="button" name="close" value='$cl' onclick="self.close()" />
1.7       harris41  194: END
1.15      harris41  195:             $groupimportbutton=<<END;
1.77      www       196: <input type="button" name="groupimport" value='$gi'
1.199     droeschl  197: onclick="javascript:select_group()" />
1.7       harris41  198: END
1.15      harris41  199:         }
1.35      matthew   200: 	# Additions made by Matthew to make the browser a little easier to deal
                    201: 	# with in the future.
                    202: 	#
                    203: 	# $mode (at this time) indicates if we are in edit mode.
                    204: 	# $form is the name of the form that the URL is placed when the
                    205: 	#       selection is made.
                    206: 	# $element is the name of the element in $formname which receives
                    207: 	#       the URL.
1.91      taceyjo1  208: 	#&Apache::lonxml::debug('Checking mode, form, element');
1.133     albertel  209: 	&setvalues(\%hash,'form.mode'        ,\%env,'form.mode'   );
                    210: 	&setvalues(\%hash,'form.form'        ,\%env,'form.form'   );
                    211: 	&setvalues(\%hash,'form.element'     ,\%env,'form.element');
                    212: 	&setvalues(\%hash,'form.titleelement',\%env,'form.titleelement');
                    213: 	&setvalues(\%hash,'form.only'        ,\%env,'form.only'   );
                    214: 	&setvalues(\%hash,'form.omit'        ,\%env,'form.omit'   );
1.35      matthew   215: 
1.40      matthew   216:         # Deal with 'omit' and 'only' 
1.133     albertel  217:         if (exists $env{'form.omit'}) {
                    218:             @Omit = split(',',$env{'form.omit'});
1.40      matthew   219:         }
1.133     albertel  220:         if (exists $env{'form.only'}) {
                    221:             @Only = split(',',$env{'form.only'});
1.40      matthew   222:         }
                    223:         
1.133     albertel  224: 	my $mode = $env{'form.mode'};
1.79      albertel  225: 	my ($form,$element,$titleelement);
1.39      matthew   226: 	if ($mode eq 'edit' || $mode eq 'parmset') {
1.133     albertel  227: 	    $form         = $env{'form.form'};
                    228: 	    $element      = $env{'form.element'};
                    229: 	    $titleelement = $env{'form.titleelement'};
1.35      matthew   230: 	}
1.90      taceyjo1  231: 	#&Apache::lonxml::debug("mode=$mode form=$form element=$element titleelement=$titleelement");
1.17      harris41  232: # ------ set catalogmodefunctions to have extra needed javascript functionality
1.15      harris41  233: 	my $catalogmodefunctions='';
1.133     albertel  234: 	if ($env{'form.catalogmode'} eq 'interactive' or
1.145     www       235: 	    $env{'form.catalogmode'} eq 'import') {
1.35      matthew   236: 	    # The if statement below sets us up to use the old version
                    237: 	    # by default (ie. if $mode is undefined).  This is the easy
                    238: 	    # way out.  Hopefully in the future I'll find a way to get 
                    239: 	    # the calls dealt with in a more comprehensive manner.
1.41      www       240: 
                    241: #
                    242: # There is now also mode "simple", which is for the simple version of the rat
                    243: #
                    244: #
1.39      matthew   245: 	    if (!defined($mode) || ($mode ne 'edit' && $mode ne 'parmset')) {
1.170     albertel  246:                 my $location = "/adm/groupsort?&inhibitmenu=yes&catalogmode=import&";
1.41      www       247:                 $location .= "mode=".$mode."&";
1.40      matthew   248:                 $location .= "acts=";
1.35      matthew   249: 		$catalogmodefunctions=<<"END";
1.108     albertel  250: function select_data(url) {
1.7       harris41  251:     changeURL(url);
1.8       harris41  252:     self.close();
                    253: }
                    254: function select_group() {
1.40      matthew   255:     window.location="$location"+document.forms.fileattr.acts.value;
1.16      harris41  256: }
1.35      matthew   257: function changeURL(val) {
                    258:     if (opener.inf) {
                    259:         if (opener.inf.document.forms.resinfo.elements.u) {
                    260: 	    opener.inf.document.forms.resinfo.elements.u.value=val;
                    261:         }
1.7       harris41  262:     }
                    263: }
1.35      matthew   264: END
1.39      matthew   265:             } elsif ($mode eq 'edit') { # we are in 'edit' mode
1.40      matthew   266:                 my $location = "/adm/groupsort?catalogmode=interactive&";
                    267:                 $location .= "form=$form&element=$element&mode=edit&acts=";
1.35      matthew   268: 		$catalogmodefunctions=<<END;
                    269: // mode = $mode
1.108     albertel  270: function select_data(url) {
                    271:    var location = "/res/?launch=2&form=$form&element=$element&titleelement=$titleelement&acts=" + url;
1.105     taceyjo1  272:    window.location=location;
1.173     banghart  273:    if (window.opener.document.forms["$form"].elements["$element"].value != url) {
                    274:        window.opener.unClean();
                    275:    }
1.35      matthew   276: }
                    277: function select_group() {
1.40      matthew   278:     window.location="$location"+document.forms.fileattr.acts.value;
1.35      matthew   279: }
                    280: 
1.7       harris41  281: function changeURL(val) {
1.35      matthew   282:     if (window.opener.document) {
                    283: 	window.opener.document.forms["$form"].elements["$element"].value=val;
                    284:     } else {
                    285: 	    alert("The file you selected is: "+val);
1.7       harris41  286:     }
                    287: }
                    288: END
1.79      albertel  289:                 if (!$titleelement) {
                    290: 		    $catalogmodefunctions.='function changeTitle(val) {}';
                    291: 		} else {
                    292: 		    $catalogmodefunctions.=<<END;
                    293: function changeTitle(val) {
                    294:     if (window.opener.document) {
                    295: 	    window.opener.document.forms["$form"].elements["$titleelement"].value=val;
                    296:     } else {
                    297: 	    alert("The title of the file you selected is: "+val);
                    298:     }
                    299: }
                    300: END
                    301:                 }
1.39      matthew   302:             } elsif ($mode eq 'parmset') {
1.40      matthew   303:                 my $location = "/adm/groupsort?catalogmode=interactive&";
                    304:                 $location .= "form=$form&element=$element&mode=parmset&acts=";
1.39      matthew   305: 		$catalogmodefunctions=<<END;
                    306: // mode = $mode
1.108     albertel  307: function select_data(url) {
1.39      matthew   308:     changeURL(url);
                    309:     self.close();
                    310: }
                    311: 
                    312: function select_group() {
1.40      matthew   313:     window.location="$location"+document.forms.fileattr.acts.value;
1.39      matthew   314: }
                    315: 
                    316: function changeURL(val) {
                    317:     if (window.opener.document) {
1.206     raeburn   318:         var elementname  = "$element";
1.39      matthew   319: 	window.opener.document.forms["$form"].elements[elementname].value=val;
                    320:     } else {
                    321: 	    alert("The file you selected is: "+val);
                    322:     }
                    323: }
                    324: 
                    325: END
                    326:             }
1.15      harris41  327:         }
1.38      matthew   328:         $catalogmodefunctions.=<<END;
                    329: var acts='';
                    330: function rep_dirpath(suffix,val) {
                    331:     eval("document.forms.dirpath"+suffix+".acts.value=val");
                    332: }
                    333: END
1.145     www       334: 	if ($env{'form.catalogmode'} eq 'import') {
1.38      matthew   335:             $catalogmodefunctions.=<<END;
1.16      harris41  336: function queue(val) {
                    337:     if (eval("document.forms."+val+".filelink.checked")) {
                    338: 	var l=val.length;
                    339: 	var v=val.substring(4,l);
                    340: 	document.forms.fileattr.acts.value+='1a'+v+'b';
                    341:     }
                    342:     else {
                    343: 	var l=val.length;
                    344: 	var v=val.substring(4,l);
                    345: 	document.forms.fileattr.acts.value+='0a'+v+'b';
                    346:     }
                    347: }
                    348: END
                    349: 	}
1.17      harris41  350: 
1.170     albertel  351:         my $inhibit_menu = "+'&".&Apache::loncommon::inhibit_menu_check()."'";
1.1       www       352: # ---------------------------------------------------------------- Print Header
1.170     albertel  353:         
1.141     albertel  354: 	my $js = <<"ENDHEADER";
1.19      harris41  355: <script type="text/javascript">
1.199     droeschl  356: // <![CDATA[
1.175     banghart  357: $catalogmodefunctions;
                    358: function update_only(field) {
                    359:     alert(field.name);
                    360: }
1.163     banghart  361: function checkAll() {
1.160     banghart  362:     var numForms = document.forms.length;
                    363:     for (i=0;i<numForms;i++) {
                    364:         var numElements = document.forms[i].elements.length;
                    365:         for (j=0;j<numElements;j++){
1.163     banghart  366:             var fieldName = document.forms[i].elements[j].name;
                    367:             if (fieldName == 'filelink') {
                    368:                 document.forms[i].elements[j].checked = true;
1.168     banghart  369:                 queue(document.forms[i].name);
1.163     banghart  370:             }
                    371:         }
                    372:     }
                    373: }
                    374: function uncheckAll() {
                    375:     var numForms = document.forms.length;
                    376:     for (i=0;i<numForms;i++) {
                    377:         var numElements = document.forms[i].elements.length;
                    378:         for (j=0;j<numElements;j++){
                    379:             var fieldName = document.forms[i].elements[j].name;
                    380:             if (fieldName == 'filelink') {
                    381:                 document.forms[i].elements[j].checked = false;
1.168     banghart  382:                 queue(document.forms[i].name);
1.160     banghart  383:             }
                    384:         }
                    385:     }
                    386: }
1.213     www       387: 
1.69      www       388: function openWindow(url, wdwName, w, h, toolbar,scrollbar,locationbar) {
1.71      ng        389:     var xpos = (screen.width-w)/2;
                    390:     xpos = (xpos < 0) ? '0' : xpos;
                    391:     var ypos = (screen.height-h)/2-30;
                    392:     ypos = (ypos < 0) ? '0' : ypos;
                    393:     var options = "width=" + w + ",height=" + h + ",screenx="+xpos+",screeny="+ypos+",";
1.2       harris41  394:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
1.69      www       395:     options += "menubar=no,toolbar="+toolbar+",location="+locationbar+",directories=no";
1.2       harris41  396:     var newWin = window.open(url, wdwName, options);
                    397:     newWin.focus();
                    398: }
1.213     www       399: 
1.16      harris41  400: function gothere(val) {
1.170     albertel  401:     window.location=val+'?acts='+document.forms.fileattr.acts.value$inhibit_menu;
1.16      harris41  402: }
1.199     droeschl  403: // ]]>
1.14      harris41  404: </script>
1.141     albertel  405: ENDHEADER
1.3       harris41  406: 
1.154     albertel  407:         my ($headerdom)=($uri=~m{^/res/($match_domain)/});
1.198     bisitz    408: 
                    409:         if ($env{'form.catalogmode'}) {
                    410:             # "Popup mode"
                    411:             $r->print(&Apache::loncommon::start_page('Browse published resources',$js,
1.213     www       412:                                                      {'only_body' => 1, 'add_wishlist'=>1, 'add_modal' =>1, 
1.198     bisitz    413:                                                       'domain' => $headerdom,}));
                    414:         } else {
                    415:             # Only display page header and breadcrumbs in non-popup mode
                    416:             &Apache::lonhtmlcommon::clear_breadcrumbs();
                    417:             &Apache::lonhtmlcommon::add_breadcrumb({
                    418:                 'text'  => 'Browse published resources',
1.216     bisitz    419:                 'href'  => '/res/'.$headerdom.'/?launch=1',
1.198     bisitz    420:             });
                    421:             $r->print(&Apache::loncommon::start_page('Browse published resources',$js,
                    422:                                                      {'domain' => $headerdom,})
                    423:                      .&Apache::lonhtmlcommon::breadcrumbs()
                    424:             );
                    425:         }
                    426: 
1.175     banghart  427: # ---------------------------------- get state of file types to be showing
                    428: 	if ($env{'form.only'}) {
1.176     banghart  429: 	    $typeselect = $env{'form.only'};
1.175     banghart  430: 	} else {
1.176     banghart  431: 	    $typeselect = '';
1.175     banghart  432: 	}
                    433: 
1.23      harris41  434: # ---------------------------------- get state of file attributes to be showing
1.133     albertel  435: 	if ($env{'form.attrs'}) {
1.195     jms       436: 	    for (my $i=0; $i<=16; $i++) {
1.6       harris41  437: 		delete $hash{'display_attrs_'.$i};
1.133     albertel  438: 		if ($env{'form.attr'.$i} == 1) {
1.45      ng        439: 		    $attrchk[$i] = 'checked';
1.6       harris41  440: 		    $hash{'display_attrs_'.$i} = 1;
                    441: 		}
                    442: 	    }
                    443: 	} else {
1.195     jms       444: 	    for (my $i=0; $i<=16; $i++) {
1.199     droeschl  445: 		$attrchk[$i] = 'checked="checked"' if $hash{'display_attrs_'.$i} == 1;
1.6       harris41  446: 	    }
                    447: 	}
1.87      www       448: 
1.205     raeburn   449:         my @file_categories = &Apache::loncommon::filecategories();
                    450:         my %select_file_categories;
                    451:         my @select_form_order = ('');
                    452:         $select_file_categories{''} = &mt('All file types');
                    453:         foreach my $cat (@file_categories) {
                    454:             my $types = join(",",&Apache::loncommon::filecategorytypes($cat));
                    455:             $select_file_categories{$types} = &mt($cat);
                    456:             push(@select_form_order,$types);
                    457:         }
                    458:         $select_file_categories{'select_form_order'} = \@select_form_order;
1.207     raeburn   459:         my $onchange = 'this.form.submit();';
1.205     raeburn   460:         my $type_element=
                    461:             &Apache::loncommon::select_form(
                    462:                 $typeselect,
                    463:                 'only',
1.207     raeburn   464:                 \%select_file_categories,$onchange);
1.205     raeburn   465:         my $type_selector = '<label>'.&mt('File Type Displayed: [_1]',
                    466:                                           $type_element).'</label>';
                    467: 
1.23      harris41  468: # ------------------------------- output state of file attributes to be showing
1.71      ng        469: #                                 All versions has to the last item
                    470: #                                 since it does not take an extra col
1.77      www       471: 	my %lt=&Apache::lonlocal::texthash(
                    472: 					   'av' => 'All versions',
1.174     banghart  473: 					   'ud' => 'Update Display',
                    474: 					   'pr' => 'Problems',
                    475: 					   'gr' => 'Graphics',
1.183     bisitz    476: 					   'at' => 'All types',
                    477: 					   'hd' => 'Display Options'
1.77      www       478: 					   );
1.205     raeburn   479:         my @disp_order = ('0','4','5','6','13','1','2','3','10','14','8','11','7','12','15','16');
                    480:         my %disp_options = &Apache::lonlocal::texthash (
                    481:                               0  => 'Title',
                    482:                               4  => 'Author',
                    483:                               5  => 'Keywords',
                    484:                               6  => 'Language',
                    485:                               13 => 'Notes',
                    486:                               1  => 'Size',
                    487:                               2  => 'Last access',
                    488:                               3  => 'Last modified',
                    489:                               10 => 'Source Available',
                    490:                               14 => 'Abstract',
                    491:                               8  => 'Statistics',
                    492:                               11 => 'Linked/Related Resources',
                    493:                               7  => 'Show resource',
                    494:                               12 => 'Subject',
                    495:                               15 => 'Grade Level',
                    496:                               16 => 'Standards',
                    497:                            );
                    498:         my $cell = 0;
                    499:         my $numinrow = 4;
                    500: 	$r->print('
                    501: <form method="post" name="fileattr" action="'.$uri.'" enctype="application/x-www-form-urlencoded">
1.183     bisitz    502: <fieldset>
1.205     raeburn   503: <legend>'.$lt{'hd'}.'</legend>
                    504: <table style=" border-collapse: collapse; border-style: none;">'."\n");
                    505:         foreach my $item (@disp_order) {
                    506:             my $style = 'padding-left: 12px; padding-right: 8px;';
                    507:             if ($cell%$numinrow == 0) {
                    508:                 $r->print('<tr>');
                    509:             }
                    510:             $cell ++;
                    511:             if ($cell > 3 * $numinrow) {
                    512:                 $style .= ' padding-bottom: 6px;'; 
                    513:             }
                    514:             if (defined($disp_options{$item})) {
                    515:                 $r->print('<td style="'.$style.'"><span class="LC_nobreak">'.
                    516:                           '<label><input type="checkbox" name="attr'.$item.'" value="1" '.
                    517:                           $attrchk[$item].' onclick="this.form.submit();" /> '.$disp_options{$item}.
                    518:                           '</label></span></td>'."\n");
                    519:             }
                    520:             if ($cell > 1 && $cell%$numinrow == 0) {
                    521:                 $r->print('</tr>');
                    522:             }
                    523:         }
                    524:         $r->print(<<END);
                    525: <tr>
                    526: <td style="font-style: italic; border-top: 1px solid black; padding-top: 6px"> 
1.199     droeschl  527: <label><input type="checkbox" name="attr9" value="1" $attrchk[9] onclick="this.form.submit();" /> $lt{'av'}</label>
1.205     raeburn   528: </td>
                    529: <td colspan="3" style="padding-left:8px; padding-top: 4px; font-style: italic; border-top: 1px solid black; padding-top: 8px">$type_selector</td>
1.115     www       530: </tr>
                    531: </table>
1.87      www       532: <input type="hidden" name="attrs" value="1" />
1.205     raeburn   533: </fieldset>
1.87      www       534: <input type="submit" name="updatedisplay" value="$lt{'ud'}" />
1.16      harris41  535: <input type="hidden" name="acts" value="" />
1.87      www       536: $closebutton $groupimportbutton
1.1       www       537: END
1.170     albertel  538:         $r->print(&Apache::loncommon::inhibit_menu_check('input'));
1.178     albertel  539:    
1.97      www       540: # -------------- Filter out sequence containment in crumbs and "recent folders"
                    541: 	my $storeuri=$uri;
                    542: 	$storeuri='/'.(split(/\.(page|sequence)\/\//,$uri))[-1];
                    543: 	$storeuri=~s/\/+/\//g;
1.82      www       544: # ---------------------------------------------------------------- Bread crumbs
1.202     bisitz    545:         $r->print(
                    546:             '<p>'
                    547:            .&Apache::lonhtmlcommon::crumbs(
                    548:                 $storeuri,
                    549:                 '',
                    550:                 '',
                    551:                 (($env{'form.catalogmode'} eq 'import')?
                    552:                                  'document.forms.fileattr':''))
                    553:            .'<br />'
                    554:            .&Apache::lonhtmlcommon::select_recent(
                    555:                 'residx',
                    556:                 'resrecent',
                    557:                 'window.status=this.form.resrecent.options[this.form.resrecent.selectedIndex].value;this.form.action=this.form.resrecent.options[this.form.resrecent.selectedIndex].value;this.form.submit();')
                    558:            .'</p>'
                    559:         );
1.100     www       560: # -------------------------------------------------------- Resource Home Button
1.133     albertel  561: 	my $reshome=$env{'course.'.$env{'request.course.id'}.'.reshome'};
1.100     www       562: 	if ($reshome) {
1.194     jms       563: 	    $r->print("<span class=\"LC_fontsize_large\"><a href='");
1.145     www       564: 	    if ($env{'form.catalogmode'} eq 'import') {
1.170     albertel  565: 		$r->print('javascript:document.forms.fileattr.action="'.&Apache::loncommon::inhibit_menu_check($reshome).'";document.forms.fileattr.submit();');
1.100     www       566: 	    } else {
                    567: 		$r->print($reshome);
                    568: 	    }
1.226     droeschl  569: 	    $r->print("'>".&mt('Home directory').'</a></span>');
1.100     www       570: 	}
                    571: 	$r->print('</form>');
1.85      www       572: # ------------------------------------------------------ Remember where we were
1.97      www       573: 	&Apache::loncommon::storeresurl($storeuri);
                    574: 	&Apache::lonhtmlcommon::store_recent('residx',$storeuri,$storeuri);
1.163     banghart  575: # -------------------------------------------------- Check All and Uncheck all
1.171     albertel  576: 	if ($env{'form.catalogmode'} eq 'import') {
1.202     bisitz    577: 	    $r->print('<p><input type="button" value="'.&mt("Check All").'" id="checkallbutton" onclick="javascript:checkAll()" />');
                    578: 	    $r->print('<input type="button" value="'.&mt("Uncheck All").'" id="uncheckallbutton" onclick="javascript:uncheckAll()" /></p>');
1.171     albertel  579: 	}
1.23      harris41  580: # ----------------- output starting row to the indexed file/directory hierarchy
1.129     albertel  581:         #$r->print(&initdebug());
                    582:         #$r->print(&writedebug("Omit:@Omit")) if (@Omit);
                    583:         #$r->print(&writedebug("Only:@Only")) if (@Only);
1.194     jms       584:         $r->print(&Apache::loncommon::start_data_table("LC_tableBrowseRes")
1.182     bisitz    585:                  .&Apache::loncommon::start_data_table_header_row());
                    586: 	$r->print("<th $colspan>".&mt('Name')."</th>\n");
1.208     wenzelju  587: 	$r->print("<th></th>\n");
1.182     bisitz    588: 	$r->print("<th>".&mt('Title')."</th>\n") 
1.45      ng        589: 	    if ($hash{'display_attrs_0'} == 1);
1.194     jms       590: 	$r->print('<th class="LC_right">'.&mt("Size")." (".&mt("bytes").") ".
1.182     bisitz    591: 		  "</th>\n") if ($hash{'display_attrs_1'} == 1);
                    592: 	$r->print("<th>".&mt("Last accessed")."</th>\n") 
1.17      harris41  593: 	    if ($hash{'display_attrs_2'} == 1);
1.182     bisitz    594: 	$r->print("<th>".&mt("Last modified")."</th>\n")
1.17      harris41  595: 	    if ($hash{'display_attrs_3'} == 1);
1.182     bisitz    596: 	$r->print("<th>".&mt("Author(s)")."</th>\n")
1.17      harris41  597: 	    if ($hash{'display_attrs_4'} == 1);
1.182     bisitz    598: 	$r->print("<th>".&mt("Keywords")."</th>\n")
1.17      harris41  599: 	    if ($hash{'display_attrs_5'} == 1);
1.182     bisitz    600: 	$r->print("<th>".&mt("Language")."</th>\n")
1.45      ng        601: 	    if ($hash{'display_attrs_6'} == 1);
1.182     bisitz    602: 	$r->print("<th>".&mt("Usage Statistics")." <br />(".
                    603: 		  &mt("Courses/Network Hits").") ".&mt('updated periodically')."</th>\n")
1.70      ng        604: 	    if ($hash{'display_attrs_8'} == 1);
1.182     bisitz    605: 	$r->print("<th>".&mt("Source Available")."</th>\n")
1.109     taceyjo1  606: 	    if ($hash{'display_attrs_10'} == 1);
1.182     bisitz    607: 	$r->print("<th>".&mt("Linked/Related Resources")."</th>\n")
1.111     www       608: 	    if ($hash{'display_attrs_11'} == 1);
1.182     bisitz    609: 	$r->print("<th>".&mt("Resource")."</th>\n")
1.115     www       610: 	    if ($hash{'display_attrs_7'} == 1);
1.185     jms       611: 	$r->print("<th>".&mt("Subject")."</th>\n")
                    612: 	    if ($hash{'display_attrs_12'} == 1);
1.186     jms       613: 	$r->print("<th>".&mt("Notes")."</th>\n")
                    614: 	    if ($hash{'display_attrs_13'} == 1);
                    615: 	$r->print("<th>".&mt("Abstract")."</th>\n")
                    616: 	    if ($hash{'display_attrs_14'} == 1);
1.193     jms       617: 	$r->print("<th>".&mt("Grade Level")."</th>\n")
                    618: 	    if ($hash{'display_attrs_15'} == 1);
1.195     jms       619: 	$r->print("<th>".&mt("Standards")."</th>\n")
                    620: 	    if ($hash{'display_attrs_16'} == 1);
1.185     jms       621: 	    
                    622:     $r->print(&Apache::loncommon::end_data_table_header_row());
                    623:     
                    624:     	
1.5       harris41  625: 
1.23      harris41  626: # ----------------- read in what directories have previously been set to "open"
1.222     raeburn   627: 	foreach (keys(%hash)) {
1.4       harris41  628: 	    if ($_ =~ /^diropen_status_/) {
                    629: 		my $key = $_;
                    630: 		$key =~ s/^diropen_status_//;
                    631: 		$dirs{$key} = $hash{$_};
                    632: 	    }
1.27      harris41  633: 	}
1.4       harris41  634: 
1.133     albertel  635: 	if ($env{'form.openuri'}) {  # take care of review and refresh options
                    636: 	    my $uri=$env{'form.openuri'};
1.4       harris41  637: 	    if (exists($hash{'diropen_status_'.$uri})) {
                    638: 		my $cursta = $hash{'diropen_status_'.$uri};
1.2       harris41  639: 		$dirs{$uri} = 'open';
1.4       harris41  640: 		$hash{'diropen_status_'.$uri} = 'open';
                    641: 		if ($cursta eq 'open') {
                    642: 		    $dirs{$uri} = 'closed';
                    643: 		    $hash{'diropen_status_'.$uri} = 'closed';
                    644: 		}
1.2       harris41  645: 	    } else {
1.4       harris41  646: 		$hash{'diropen_status_'.$uri} = 'open';
1.2       harris41  647: 		$dirs{$uri} = 'open';
                    648: 	    }
                    649: 	}
1.12      ng        650: 	
                    651: 	my $toplevel;
1.13      ng        652: 	my $indent = 0;
1.12      ng        653: 	$uri = $uri.'/' if $uri !~ /.*\/$/;
1.17      harris41  654: 
1.133     albertel  655:  	if ($env{'form.dirPointer'} ne 'on') {
1.88      www       656:  	    $hash{'top.level'} = $uri;
                    657:  	    $toplevel = $uri;
                    658:  	} else {
                    659:  	    $toplevel = $hash{'top.level'};
                    660:  	}
1.17      harris41  661: 
1.23      harris41  662: # -------------------------------- if not at top level, provide an uplink arrow
1.45      ng        663: 	if ($toplevel ne '/res/'){
1.13      ng        664: 	    my (@uri_com) = split(/\//,$uri);
                    665: 	    pop @uri_com;
                    666: 	    my $upone = join('/',@uri_com);
                    667: 	    my @list = qw (0);
1.227     raeburn   668: 	    &display_line ($r,$defdom,'opened',$upone.'&viewOneUp',0,$upone,@list);
1.13      ng        669: 	    $indent = 1;
1.12      ng        670: 	}
1.17      harris41  671: 
1.23      harris41  672: # -------- recursively go through all the directories and output as appropriate
1.227     raeburn   673: 	&scanDir ($r,$toplevel,$indent,\%hash,$defdom);
1.152     albertel  674: 
                    675: # -------------------------------------------------------------- end the tables
1.182     bisitz    676:         $r->print(&Apache::loncommon::end_data_table());
                    677: 
1.23      harris41  678: # ---------------------------- embed hidden information useful for group import
1.152     albertel  679: 	$r->print("<form name='fnum' action=''>");
1.131     albertel  680: 	$r->print("<input type='hidden' name='fnum' value='$fnum' /></form>");
1.17      harris41  681: 
1.23      harris41  682: # --------------------------------------------------- end the output and return
1.141     albertel  683: 	$r->print(&Apache::loncommon::end_page()."\n");
1.2       harris41  684:     }
1.67      matthew   685:     if(! $c->aborted()) {
1.87      www       686: # write back into the temporary file
1.68      albertel  687: 	my %dbfile;
1.67      matthew   688:         if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_NEWDB(),0640)) {
                    689:             while (my($key,$value) = each(%hash)) {
                    690:                 $dbfile{$key}=$value;
                    691:             }
                    692:             untie(%dbfile);
                    693:         }
                    694:     }
                    695: 
1.1       www       696:     return OK;
                    697: }
1.2       harris41  698: 
1.17      harris41  699: # ----------------------------------------------- recursive scan of a directory
1.2       harris41  700: sub scanDir {
1.227     raeburn   701:     my ($r,$startdir,$indent,$hashref,$defdom)=@_;
1.67      matthew   702:     my $c = $r->connection();
1.3       harris41  703:     my ($compuri,$curdir);
                    704:     my $dirptr=16384;
1.90      taceyjo1  705:     my $obs;
1.1       www       706:     $indent++;
1.2       harris41  707:     my %dupdirs = %dirs;
                    708:     my @list=&get_list($r,$startdir);
                    709:     foreach my $line (@list) {
1.67      matthew   710:         return if ($c->aborted());
1.90      taceyjo1  711: 	#This is a kludge, sorry aboot this
1.92      taceyjo1  712: 	my ($strip,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
1.224     raeburn   713: 	next if (($strip =~ /\.meta$/) || ($obs));
1.225     raeburn   714:         if ($dom ne 'domain') {
                    715:             my ($udom,$uname);
                    716:             if ($dom eq 'user') {
                    717:                 ($udom) = ($startdir =~ m{^/res/($match_domain)});
                    718:                 $uname = $strip;
                    719:             } else {
                    720:                 ($udom,$uname) = ($startdir =~ m{^/res/($match_domain)/($match_courseid)});
                    721:             }
                    722:             if ($udom ne '' && $uname ne '') {
                    723:                 # Don't display "course author" directory.
1.229     raeburn   724:                 next if (&Apache::lonnet::is_course($udom,$uname));
1.225     raeburn   725:             }
                    726:         }
1.18      ng        727: 	my (@fileparts) = split(/\./,$strip);
1.70      ng        728: 	if ($hash{'display_attrs_9'} != 1) {
1.181     bisitz    729:             # if not all versions to be shown
1.18      ng        730: 	    if (scalar(@fileparts) >= 3) {
                    731: 		my $fext = pop @fileparts;
                    732: 		my $ov = pop @fileparts;
                    733: 		my $fname = join ('.',@fileparts,$fext);
1.75      albertel  734: 		next if (grep /\Q$fname\E/,@list and $ov =~ /^\d+$/);
1.18      ng        735: 	    }
                    736: 	}
                    737: 
1.45      ng        738: 	if ($dom eq 'domain') {
1.72      albertel  739: 	    # dom list has full path /res/<domain name>/ already
                    740: 	    $curdir='';
1.73      albertel  741: 	    $compuri = (split(/\&/,$line))[0];
1.2       harris41  742: 	} else {
1.17      harris41  743: 	    # user, dir & file have name only, i.e., w/o path
1.45      ng        744: 	    $compuri = join('',$startdir,$strip,'/');
1.3       harris41  745: 	    $curdir = $startdir;
1.2       harris41  746: 	}
1.45      ng        747: 	my $diropen = 'closed';
1.96      www       748: 	if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/) or ($compuri=~/\.(sequence|page)\/$/)) {
1.3       harris41  749: 	    while (my ($key,$val)= each %dupdirs) {
1.5       harris41  750: 		if ($key eq $compuri and $val eq "open") {
1.11      ng        751: 		    $diropen = "opened";
1.53      albertel  752: 		    delete($dupdirs{$key});
                    753: 		    delete($dirs{$key});
1.5       harris41  754: 		}
1.3       harris41  755: 	    }
1.1       www       756: 	}
1.227     raeburn   757: 	&display_line($r,$defdom,$diropen,$line,$indent,$curdir,$hashref,@list);
                    758: 	&scanDir ($r,$compuri,$indent,undef,$defdom) if $diropen eq 'opened';
1.1       www       759:     }
                    760:     $indent--;
                    761: }
                    762: 
1.17      harris41  763: # --------------- get complete matched list based on the uri (returns an array)
1.1       www       764: sub get_list {
                    765:     my ($r,$uri)=@_;
1.97      www       766:     my @list=();
1.211     raeburn   767:     my $listerror;
1.210     dseaton   768:     
1.45      ng        769:     (my $luri = $uri) =~ s/\//_/g;
1.133     albertel  770:     if ($env{'form.updatedisplay'}) {
1.222     raeburn   771: 	foreach (keys(%hash)) {
1.4       harris41  772: 	    delete $hash{$_} if ($_ =~ /^dirlist_files_/);
1.121     albertel  773: 	    delete $hash{$_} if ($_ =~ /^dirlist_timestamp_files_/);
1.87      www       774: 	}
1.2       harris41  775:     }
                    776: 
1.121     albertel  777:     if (defined($hash{'dirlist_files_'.$luri}) &&
                    778: 	$hash{'dirlist_timestamp_files_'.$luri}+600 > (time)) {
1.4       harris41  779: 	@list = split(/\n/,$hash{'dirlist_files_'.$luri});
1.97      www       780:     } elsif ($uri=~/\.(page|sequence)\/$/) {
1.94      www       781: # is a page or a sequence
1.97      www       782: 	$uri=~s/\/$//;
                    783: 	$uri='/'.(split(/\.(page|sequence)\/\//,$uri))[-1];
                    784: 	$uri=~s/\/+/\//g;
                    785: 	foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$uri))) {
                    786: 	    my @ratpart=split(/\:/,$_);
1.156     albertel  787: 	    push(@list,&LONCAPA::map::qtescape($ratpart[1]));
1.97      www       788: 	} 
1.94      www       789: 	$hash{'dirlist_files_'.$luri} = join("\n",@list);
1.1       www       790:     } else {
1.94      www       791: # is really a directory
1.211     raeburn   792: 	(my $listref,$listerror) = &Apache::lonnet::dirlist($uri);
                    793:         if (ref($listref) eq 'ARRAY') {
                    794:             @list = @{$listref};
                    795:         }
1.87      www       796: 	$hash{'dirlist_files_'.$luri} = join("\n",@list);
1.121     albertel  797: 	$hash{'dirlist_timestamp_files_'.$luri} = time;
1.1       www       798:     }
1.210     dseaton   799: #Checking for error messages associated with empty directories or inaccessible servers (See Bug 4984)
1.212     www       800:     if (($listerror eq 'no_such_dir') || ($listerror eq 'no_such_host') || ($listerror eq 'no_host')) { 
1.210     dseaton   801:         $r->print("<p class='LC_info'>" . &mt("Directory does not exist."). "</p>");
1.211     raeburn   802:     } elsif ($listerror eq 'con_lost') {
1.210     dseaton   803:         $r->print("<p class='LC_info'>" . &mt("Directory temporarily not accessible."). "</p>");
                    804:     }
                    805: 
1.156     albertel  806:     return @list=&match_ext($r,@list);    
1.1       www       807: }
                    808: 
1.112     www       809: sub dynmetaread {
                    810:     my $uri=shift;
                    811:     if (($hash{'display_attrs_8'}==1) || ($hash{'display_attrs_11'}==1)) {
1.117     www       812: # We don't want the filename
                    813: 	$uri=~s/\/[^\/]+$//;
                    814: # Did we already see this?
                    815: 	my $builddir=$uri;
                    816: 	while ($builddir) {
                    817: 	    if ($dynread{$builddir}) {
                    818: 		return 0;
                    819: 	    }
                    820: 	    $builddir=~s/\/[^\/]+$//;
                    821: 	}
                    822: # Actually get the data
1.112     www       823: 	%dynhash=
1.143     www       824: 	    (%dynhash,&Apache::lonmeta::get_dynamic_metadata_from_sql($uri.'/'));
1.117     www       825: # Remember that we got it
                    826: 	$dynread{$uri}=1;
1.112     www       827:     } 
                    828: }
                    829: 
1.40      matthew   830: sub initdebug {
1.141     albertel  831:     my $start_page=
                    832: 	&Apache::loncommon::start_page('Debug',undef,
                    833: 				       {'only_body' => 1,});
                    834:     $start_page =~ s/\n/ /g;
1.40      matthew   835:     return <<ENDJS;
1.141     albertel  836: <script type="text/javascript">
1.40      matthew   837: var debugging = true;
                    838: if (debugging) {
                    839:     var debuggingWindow = window.open('','Debug','width=400,height=300',true);
                    840: } 
                    841: 
                    842: function output(text) {
                    843:     if (debugging) {
                    844:         debuggingWindow.document.writeln(text);
                    845:     }
                    846: }
1.141     albertel  847: output('$start_page<pre>');   
1.40      matthew   848: </script>
                    849: ENDJS
                    850: }
                    851: 
                    852: sub writedebug {
1.141     albertel  853:     my ($text) = @_;
                    854:     return "<script type=\"text/javascript\">output('$text');</script>";
1.40      matthew   855: }
                    856: 
1.17      harris41  857: # -------------------- filters out files based on extensions (returns an array)
1.1       www       858: sub match_ext {
                    859:     my ($r,@packlist)=@_;
                    860:     my @trimlist;
                    861:     my $nextline;
                    862:     my @fileext;
                    863:     my $dirptr=16384;
                    864: 
1.2       harris41  865:     foreach my $line (@packlist) {
                    866: 	chomp $line;
                    867: 	$line =~ s/^\/home\/httpd\/html//;
                    868: 	my @unpackline = split (/\&/,$line);
1.45      ng        869: 	next if ($unpackline[0] eq '.');
                    870: 	next if ($unpackline[0] eq '..');
1.2       harris41  871: 	my @filecom = split (/\./,$unpackline[0]);
                    872: 	my $fext = pop(@filecom);
1.96      www       873: 	my $fnptr = ($unpackline[3]&$dirptr) || ($fext=~/\.(page|sequence)$/);
1.2       harris41  874:  	if ($fnptr == 0 and $unpackline[3] ne "") {
1.28      harris41  875: 	    my $embstyle = &Apache::loncommon::fileembstyle($fext);
1.25      matthew   876:             push @trimlist,$line if (defined($embstyle) && 
1.32      harris41  877: 				     ($embstyle ne 'hdn' or $fext eq 'meta'));
1.1       www       878: 	} else {
1.2       harris41  879: 	    push @trimlist,$line;
1.1       www       880: 	}
                    881:     }
1.80      albertel  882:     @trimlist = sort {uc($a) cmp uc($b)} (@trimlist);
1.1       www       883:     return @trimlist;
                    884: }
                    885: 
1.17      harris41  886: # ------------------------------- displays one line in appropriate table format
1.23      harris41  887: sub display_line {
1.227     raeburn   888:     my ($r,$defdom,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
1.53      albertel  889:     my (@pathfn, $fndir);
1.97      www       890: # there could be relative paths (files actually belonging into this directory)
                    891: # or absolute paths (for example, from sequences)
                    892:     my $absolute;
                    893:     my $pathprefix;
1.107     albertel  894:     if ($line=~m|^/res/| && $startdir ne '') {
1.97      www       895: 	$absolute=1;
                    896: 	$pathprefix='';
                    897:     } else {
                    898: 	$absolute=0;
                    899: 	$pathprefix=$startdir;
                    900:     }
1.1       www       901:     my $dirptr=16384;
1.182     bisitz    902: #SB my $fileclr="#ffffe6";
1.45      ng        903:     my $iconpath= $r->dir_config('lonIconsURL') . '/';
1.1       www       904: 
                    905:     my @filecom = split (/\&/,$line);
                    906:     my @pathcom = split (/\//,$filecom[0]);
                    907:     my $listname = $pathcom[scalar(@pathcom)-1];
                    908:     my $fnptr = $filecom[3]&$dirptr;
1.77      www       909:     my $msg = &mt('View').' '.$filecom[0].' '.&mt('resources');
                    910:     $msg = &mt('Close').' '.$filecom[0].' '.&mt('directory') if $diropen eq 'opened';
1.194     jms       911:     my $nowOpen = ($diropen eq 'opened' ? 1 : 0);
1.1       www       912: 
1.45      ng        913:     my $tabtag='</td>';
1.1       www       914:     my $i=0;
1.195     jms       915:     while ($i<=16) {
1.45      ng        916: 	$tabtag=join('',$tabtag,"<td>&nbsp;</td>")
1.155     albertel  917: 	    if ($i != 9 &&
                    918: 		$hash{'display_attrs_'.$i} == 1);
1.194     jms       919: 	$i++;
1.1       www       920:     }
1.63      ng        921:     my $valign = ($hash{'display_attrs_7'} == 1 ? 'top' : 'bottom');
1.17      harris41  922: 
                    923: # display uplink arrow
1.45      ng        924:     if ($filecom[1] eq 'viewOneUp') {
1.98      www       925: 	my $updir=$startdir;
                    926: # -------------- Filter out sequence containment in crumbs and "recent folders"
                    927: 	$updir='/'.(split(/\.(page|sequence)\/\//,$startdir))[-1];
                    928: 	$updir=~s/\/+/\//g;
                    929: 
1.182     bisitz    930: #SB	$r->print("<tr valign='$valign' bgcolor=\"$fileclr\">$extrafield");
                    931:         $r->print(&Apache::loncommon::start_data_table_row()); # valign="$valign" ?!?
                    932:         $r->print($extrafield);
1.70      ng        933: 	$r->print("<td>\n");
1.98      www       934: 	$r->print ('<form method="post" name="dirpathUP" action="'.$updir.
1.16      harris41  935: 		   '/" '.
1.199     droeschl  936: 		   'onsubmit="return rep_dirpath(\'UP\','.
1.17      harris41  937: 		   'document.forms.fileattr.acts.value)" '.
1.16      harris41  938: 		   'enctype="application/x-www-form-urlencoded"'.
                    939:                    '>'."\n");
1.170     albertel  940: 	$r->print(&Apache::loncommon::inhibit_menu_check('input'));
1.197     bisitz    941: 	$r->print ('<input type="hidden" name="openuri" value="'.
1.131     albertel  942: 		   $startdir.'" />'."\n");
1.194     jms       943:         $r->print ('<input type="hidden" name="acts" value="" />'."\n");
1.199     droeschl  944: 	$r->print ('<a href="#" onclick="document.dirpathUP.submit()"><img src="'.$iconpath.'arrow.up.gif"');
                    945: 	$r->print (' alt="'.$msg.'" class="LC_fileicon" />'.
1.17      harris41  946: 		   "\n");
1.208     wenzelju  947: 	$r->print(&mt("Up")."</a></form></td><td>$tabtag");
1.182     bisitz    948:         $r->print(&Apache::loncommon::end_data_table_row());
1.13      ng        949: 	return OK;
                    950:     }
1.97      www       951: # Do we have permission to look at this?
1.201     raeburn   952:     if($filecom[15] ne '1') { return OK if ((!&Apache::lonnet::allowed('bre',$pathprefix.$filecom[0])) && (!&Apache::lonnet::allowed('bro',$pathprefix.$filecom[0]))); }
1.97      www       953: 
1.227     raeburn   954:     if (($filecom[1] eq 'domain') && ($defdom ne $listname)) {
                    955:         unless (&Apache::lonnet::will_trust('shared',$listname,$defdom)) {
                    956:             return OK;   
                    957:         }
                    958:         unless (&Apache::lonnet::will_trust('content',$defdom,$listname)) {
                    959:             return OK;
                    960:         }
                    961:     }
                    962: 
1.97      www       963: # make absolute links appear on different background
1.182     bisitz    964: #SB    if ($absolute) { $fileclr='#ccdd99'; }
1.17      harris41  965: 
                    966: # display domain
1.45      ng        967:     if ($filecom[1] eq 'domain') {
1.131     albertel  968:  	$r->print ('<input type="hidden" name="dirPointer" value="on" />'."\n")
1.133     albertel  969:  	    if ($env{'form.dirPointer'} eq "on");
1.182     bisitz    970: #SB	$r->print("<tr valign='$valign' bgcolor=\"$fileclr\">$extrafield");
                    971: 	$r->print(&Apache::loncommon::start_data_table_row()); # valign="$valign" ?!?"
                    972:         $r->print($extrafield);
1.70      ng        973: 	$r->print("<td>");
1.73      albertel  974: 	&begin_form ($r,$filecom[0]);
                    975: 	my $anchor = $filecom[0];
1.162     albertel  976: 	$anchor =~ s/\W//g;
1.152     albertel  977: 	$r->print ('<a name="'.$anchor.'"></a>');
1.194     jms       978: $r->print ('<input type="hidden" name="acts" value="" />');
1.199     droeschl  979: 	$r->print ('<a href="#" onclick="document.dirpath'.($dnum-1).'.submit()"><img src="'.$iconpath.'arrow.'.($nowOpen ? "open" : "closed" ).'.gif"'); 
                    980: 	$r->print (' alt="'.$msg.'" class="LC_fileicon" /></a>'.
1.17      harris41  981: 		   "\n");
1.128     foxr      982: 	my $quotable_filecom = &Apache::loncommon::escape_single($filecom[0]);
1.125     foxr      983: 	$r->print ('<a href="javascript:gothere(\''.$quotable_filecom.
1.152     albertel  984: 		   '\')"><img alt="" src="'.$iconpath.'server.gif"');
1.194     jms       985: 	$r->print (' class="LC_fileicon" />'."\n");
                    986: 	$r->print (&mt("Domain")." - $listname </a>");
1.158     albertel  987: 	if (&Apache::lonnet::domain($listname,'description')) {
1.194     jms       988: 	    $r->print("<br />(".&Apache::lonnet::domain($listname,'description').
1.60      albertel  989: 		      ")");
                    990: 	}
1.208     wenzelju  991: 	$r->print("</form></td><td>$tabtag");
1.182     bisitz    992:          $r->print(&Apache::loncommon::end_data_table_row());
1.1       www       993: 	return OK;
1.17      harris41  994: 
                    995: # display user directory
1.1       www       996:     }
1.227     raeburn   997: 
1.45      ng        998:     if ($filecom[1] eq 'user') {
1.227     raeburn   999:         my $domain=(split(m|/|,$startdir))[2];
                   1000:         if ($defdom ne $domain) {
                   1001:             unless (&Apache::lonnet::will_trust('shared',$domain,$defdom)) {
                   1002:                 return OK;
                   1003:             }
                   1004:             unless (&Apache::lonnet::will_trust('content',$defdom,$domain)) {
                   1005:                 return OK;
                   1006:             }
                   1007:         }
1.160     banghart 1008: 	# $r->print("<tr valign=$valign bgcolor=\"$fileclr\">$extrafield");
1.2       harris41 1009: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41 1010: 	my $anchor = $curdir;
1.162     albertel 1011: 	$anchor =~ s/\W//g;
1.182     bisitz   1012: #SB	$r->print("<tr bgcolor=\"$fileclr\">$extrafield<td valign=$valign>");
                   1013:         $r->print(&Apache::loncommon::start_data_table_row()
1.194     jms      1014:                  .$extrafield.'<td class="LC_'.$valign.'">');
1.13      ng       1015: 	&begin_form ($r,$curdir);
1.152     albertel 1016: 	$r->print ('<a name="'.$anchor.'"></a><img alt="" src="'.$iconpath.
1.194     jms      1017: 		   'whitespace_21.gif" class="LC_icon" />'."\n");
1.131     albertel 1018: 	$r->print ('<input type="hidden" name="acts" value="" />');
1.199     droeschl 1019: 	$r->print ('<a href="#" onclick="document.dirpath'.($dnum-1).'.submit()">');
1.194     jms      1020:         $r->print ('<img src="'.$iconpath.'arrow.'.($nowOpen ? "open" : "closed" ).
                   1021: 		   '.gif" class="LC_fileicon"'); 
1.199     droeschl 1022: 	$r->print (' alt="'.$msg.'"/></a>'.
1.17      harris41 1023: 		   "\n");
1.128     foxr     1024: 	my $quotable_curdir = &Apache::loncommon::escape_single($curdir);
1.223     raeburn  1025:         my $quotable_startdir = &Apache::loncommon::escape_single($startdir);
                   1026:         my $quotable_listname = &Apache::loncommon::escape_single($listname);
                   1027: 
1.125     foxr     1028: 	$r->print ('<a href="javascript:gothere(\''.$quotable_curdir
1.162     albertel 1029: 		   .'\')"><img alt="'.$msg.'" src="'.
1.194     jms      1030: 		   $iconpath.'quill.gif" class="LC_fileicon" />');
1.60      albertel 1031: 	my $domain=(split(m|/|,$startdir))[2];
                   1032: 	my $plainname=&Apache::loncommon::plainname($listname,$domain);
1.194     jms      1033:         $r->print ($listname.'</a>');
                   1034: 
                   1035:         if (defined($plainname) && $plainname) { $r->print(" ($plainname) "); }
1.208     wenzelju 1036: # Wishlistlink
                   1037:         $r->print('</form></td><td><a href="javascript:;" '.
1.214     raeburn  1038:                   'title="'.&mt('Save a link for this folder in your personal Stored Links repository').'" '.
1.223     raeburn  1039:                   'onclick="set_wishlistlink('."'$plainname','$quotable_startdir$quotable_listname"."/'".')">'.
1.208     wenzelju 1040:                   '<img class="LC_icon" src="/res/adm/pages/wishlist.png" '.
1.214     raeburn  1041:                   'alt="'.&mt('save in Stored Links').'" style="width:22px;"/></a>'.$tabtag);
1.182     bisitz   1042:         $r->print(&Apache::loncommon::end_data_table_row());
1.194     jms      1043:         return OK;
1.1       www      1044:     }
1.17      harris41 1045: 
1.1       www      1046: # display file
1.194     jms      1047:         if (($fnptr == 0 and $filecom[3] ne '') or $absolute) {
                   1048:             my $title;
                   1049:             my $filelink = $pathprefix.$filecom[0];
                   1050:             if ($hash{'display_attrs_0'} == 1) {
                   1051:                 $title = &Apache::lonnet::gettitle($filelink);
                   1052:             }
                   1053:             my @file_ext = split (/\./,$listname);
                   1054:             my $curfext = $file_ext[-1];
                   1055:             if (@Omit) {
                   1056:                 foreach (@Omit) { return OK if (lc($curfext) eq $_); }
                   1057:             }
                   1058:             if (@Only) {
                   1059:                 my $skip = 1;
                   1060:                 foreach (@Only) { $skip = 0 if (lc($curfext) eq $_); }
                   1061:                 return OK if ($skip > 0);
                   1062:             }
                   1063:             # Set the icon for the file
                   1064:             my $iconname = &Apache::loncommon::icon($listname);
1.184     bisitz   1065: #SB	$r->print("<tr valign='$valign' bgcolor=\"$fileclr\">);
1.194     jms      1066:         $r->print(&Apache::loncommon::start_data_table_row()); #SB valign="$valign" ?!?
                   1067:         $r->print('<td class="LC_middle LC_nobreak">');
1.104     albertel 1068: 	
1.133     albertel 1069:         if ($env{'form.catalogmode'} eq 'interactive') {
1.128     foxr     1070: 	    my $quotable_filelink = &Apache::loncommon::escape_single($filelink);
1.35      matthew  1071:             $r->print("<a href=\"javascript:select_data(\'",
1.125     foxr     1072:                       $quotable_filelink,"')\">");
1.162     albertel 1073: 	    $r->print("<img alt=\"\" src='",$iconpath,"select.gif' class='LC_icon' /></a>".
1.17      harris41 1074: 		      "\n");
1.199     droeschl 1075: 	    $r->print('</td><td class="LC_middle">');
1.145     www      1076: 	} elsif ($env{'form.catalogmode'} eq 'import') {
1.152     albertel 1077: 	    $r->print("<form name='form$fnum' action=''>\n");
1.8       harris41 1078: 	    $r->print("<input type='checkbox' name='filelink"."' ".
1.199     droeschl 1079: 		      "value='$filelink' onclick='".
1.16      harris41 1080: 		      "javascript:queue(\"form$fnum\")' ");
                   1081: 	    if ($hash{'store_'.$filelink}) {
                   1082: 		$r->print("checked");
                   1083: 	    }
1.131     albertel 1084: 	    $r->print(" />\n");
1.199     droeschl 1085: 	    $r->print('</form></td><td class="LC_middle">');
1.16      harris41 1086: 	    $hash{"pre_${fnum}_link"}=$filelink;
1.166     banghart 1087: 	    $hash{"pre_${fnum}_title"}=$title;
1.165     banghart 1088: 	    if (!$hash{"pre_${fnum}_title"}) {
1.167     banghart 1089: 	        $hash{"pre_${fnum}_title"} = 'Not_retrieved';
1.165     banghart 1090: 	    }
1.8       harris41 1091:   	    $fnum++;
1.7       harris41 1092: 	}
1.95      www      1093: # Form to open or close sequences
                   1094: 	if ($filelink=~/\.(page|sequence)$/) {
                   1095: 	    my $curdir = $startdir.$filecom[0].'/';
                   1096: 	    &begin_form($r,$curdir);
                   1097: 	    $indent--;
                   1098: 	}
                   1099: # General indentation
1.4       harris41 1100: 	    my $count = 0;
1.194     jms      1101: 	    while ($count < $indent) {
1.199     droeschl 1102:             $r->print('<img alt="" src="'.$iconpath.'whitespace_21.gif" 
                   1103:                 class="LC_icon" />');
1.194     jms      1104: 	        $count++;
1.4       harris41 1105: 	    }
1.95      www      1106: # Sequence open/close icon
                   1107: 	if ($filelink=~/\.(page|sequence)$/) {
                   1108: 	    my $curdir = $startdir.$filecom[0].'/';
                   1109: 	    my $anchor = $curdir;
1.162     albertel 1110: 	    $anchor =~ s/\W//g;
1.131     albertel 1111: 	    $r->print ('<input type="hidden" name="acts" value="" />');
1.194     jms      1112: 	    $r->print ('<a name="'.$anchor.'"></a>');
1.199     droeschl 1113:             $r->print ('<a href="#" onclick="document.dirpath'.($dnum-1).'.submit()">');
1.194     jms      1114:             $r->print ('<img src="'.$iconpath.'arrow.'.($nowOpen ? "open" : "closed" ).
                   1115:                        '.gif" class="LC_fileicon"');
1.199     droeschl 1116: 	    $r->print (' alt="'.$msg.'" /></a>'.
1.95      www      1117: 		       "\n");
                   1118: 	}
                   1119: # Filetype icons
1.194     jms      1120: 	$r->print("<img alt=\"\" src='$iconname' class='LC_fileicon' />\n");
1.128     foxr     1121: 	my $quotable_filelink = &Apache::loncommon::escape_single($filelink);
1.223     raeburn  1122:         my $quotable_startdir = Apache::loncommon::escape_single($startdir);
                   1123:         my $quotable_listname = &Apache::loncommon::escape_single($listname);
1.230   ! raeburn  1124:         my $curfext = lc((split(/\./,$listname))[-1]);
        !          1125:         my $modalstyle;
        !          1126:         if ($curfext =~ /^js|css|txt|tab$/) {
        !          1127:             $modalstyle = ",'','background-color:#ffffff'";
        !          1128:         }
1.125     foxr     1129: 
1.230   ! raeburn  1130: 	$r->print (" <a href=\"javascript:openMyModal('".$quotable_filelink."?inhibitmenu=yes',500,500,'yes'".$modalstyle.");\">$listname</a> ");
1.170     albertel 1131: 	$quotable_filelink = &Apache::loncommon::escape_single($filelink.'.meta');
                   1132: 	&Apache::loncommon::inhibit_menu_check(\$quotable_filelink);
1.213     www      1133: 	$r->print (" (<a href=\"javascript:openMyModal('".$quotable_filelink."?inhibitmenu=yes',500,500,'yes');\">".&mt('metadata')."</a>) ");
1.134     www      1134: # Close form to open/close sequence
                   1135: 	if ($filelink=~/\.(page|sequence)$/) {
                   1136: 	    $r->print('</form>');
                   1137: 	}
1.199     droeschl 1138: 	$r->print("</td>\n");
1.208     wenzelju 1139: # Wishlistlink
1.214     raeburn  1140:         $r->print('<td><a href="javascript:;" title="'.&mt('Save a link for this resource in your personal Stored Links repository').'" '.
1.208     wenzelju 1141:                   'onclick="set_wishlistlink('."'".&Apache::lonnet::gettitle($filelink).
1.223     raeburn  1142:                   "','$quotable_startdir$quotable_listname'".')">'.
1.208     wenzelju 1143:                   '<img class="LC_icon" src="/res/adm/pages/wishlist.png" '.
1.214     raeburn  1144:                   'alt="'.&mt('save in Stored Links').'" style="width:22px;"/></a></td>');
1.45      ng       1145: 	if ($hash{'display_attrs_0'} == 1) {
1.70      ng       1146: 	    $r->print('<td> '.($title eq '' ? '&nbsp;' : $title).
1.45      ng       1147: 		      ' </td>'."\n");
                   1148: 	}
1.194     jms      1149: 	$r->print('<td class="LC_right"> ',
1.17      harris41 1150: 		  $filecom[8]," </td>\n") 
1.45      ng       1151: 	    if $hash{'display_attrs_1'} == 1;
1.194     jms      1152: 	$r->print('<td class="LC_nobreak"> '.
1.181     bisitz   1153:                   (&Apache::lonlocal::locallocaltime($filecom[9]))." </td>\n")
1.45      ng       1154: 	    if $hash{'display_attrs_2'} == 1;
1.194     jms      1155: 	$r->print('<td class="LC_nobreak"> '.
1.181     bisitz   1156:                   (&Apache::lonlocal::locallocaltime($filecom[10]))." </td>\n")
1.45      ng       1157: 	    if $hash{'display_attrs_3'} == 1;
1.2       harris41 1158: 
1.45      ng       1159: 	if ($hash{'display_attrs_4'} == 1) {
1.104     albertel 1160: 	    my $author = &Apache::lonnet::metadata($filelink,'author');
1.194     jms      1161: 	    $r->print('<td class="LC_nobreak"> '.($author eq '' ? '&nbsp;' : $author).
1.17      harris41 1162: 		      " </td>\n");
1.2       harris41 1163: 	}
1.45      ng       1164: 	if ($hash{'display_attrs_5'} == 1) {
1.104     albertel 1165: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
1.45      ng       1166: 	    # $keywords = '&nbsp;' if (!$keywords);
1.70      ng       1167: 	    $r->print('<td> '.($keywords eq '' ? '&nbsp;' : $keywords).
1.17      harris41 1168: 		      " </td>\n");
1.2       harris41 1169: 	}
1.109     taceyjo1 1170: 
1.45      ng       1171: 	if ($hash{'display_attrs_6'} == 1) {
1.104     albertel 1172: 	    my $lang = &Apache::lonnet::metadata($filelink,'language');
1.28      harris41 1173: 	    $lang = &Apache::loncommon::languagedescription($lang);
1.70      ng       1174: 	    $r->print('<td> '.($lang eq '' ? '&nbsp;' : $lang).
1.17      harris41 1175: 		      " </td>\n");
1.2       harris41 1176: 	}
1.70      ng       1177: 	if ($hash{'display_attrs_8'} == 1) {
1.111     www      1178: # statistics
1.117     www      1179: 	    &dynmetaread($filelink);
1.112     www      1180: 	    $r->print("<td>");
1.196     droeschl 1181: 
                   1182:         for (qw(count course stdno avetries difficulty disc clear technical
                   1183:             correct helpful depth)) {
                   1184: 
                   1185:             dynmetaprint($r,$filelink,$_);
                   1186:         }
                   1187: 
1.112     www      1188: 	    $r->print("&nbsp;</td>\n");
1.111     www      1189: 
1.70      ng       1190: 	}
1.109     taceyjo1 1191: 	if ($hash{'display_attrs_10'} == 1) {
                   1192: 	    my $source = &Apache::lonnet::metadata($filelink,'sourceavail');
1.110     albertel 1193: 	    if($source eq 'open') {
1.119     taceyjo1 1194: 		my $sourcelink = &Apache::lonsource::make_link($filelink,$listname);
1.128     foxr     1195: 		my $quotable_sourcelink = &Apache::loncommon::escape_single($sourcelink);
1.170     albertel 1196: 		&Apache::loncommon::inhibit_menu_check(\$quotable_sourcelink);
1.125     foxr     1197: 		$r->print('<td>'."<a href=\"javascript:openWindow('"
                   1198: 			  .$quotable_sourcelink.
1.152     albertel 1199: 			  "', 'previewsource', '700', '700', 'no', 'yes','yes');\"".
1.181     bisitz   1200: 			  " target=\"_self\">".&mt('Source Code')."</a> "."</td>\n");
1.110     albertel 1201: 	    } else { #A cuddled else. :P
1.111     www      1202: 		$r->print("<td>&nbsp;</td>\n");
1.110     albertel 1203: 	    }
1.109     taceyjo1 1204: 	}
1.111     www      1205: 	if ($hash{'display_attrs_11'} == 1) {
                   1206: # links
1.117     www      1207: 	   &dynmetaread($filelink);
1.113     www      1208: 	   $r->print('<td>');
1.148     www      1209: 	   &coursecontext($r,$filelink);
1.196     droeschl 1210:        for (qw(goto_list comefrom_list sequsage_list dependencies course_list)) {
                   1211:              dynmetaprint($r,$filelink,$_);
                   1212:        }
1.113     www      1213: 	   $r->print('</td>');
1.114     www      1214:         }
1.185     jms      1215:         
                   1216:    
                   1217: 	
                   1218: 	if ($hash{'display_attrs_7'} == 1) {
1.115     www      1219: # Show resource
1.140     www      1220: 	   my $output=&showpreview($filelink);
1.200     droeschl 1221:            $r->print('<td class="LC_fontsize_medium">'.($output eq '' ? '&nbsp;':$output).
1.115     www      1222: 		      " </td>\n");
1.1       www      1223:     }
1.185     jms      1224:     
                   1225:     if ($hash{'display_attrs_12'} == 1) {
                   1226: 	    my $subject = &Apache::lonnet::metadata($filelink,'subject');
                   1227: 	    $r->print('<td> '.($subject eq '' ? '&nbsp;' : $subject).
                   1228: 		      " </td>\n");
                   1229: 	}
                   1230: 	
1.186     jms      1231: 	if ($hash{'display_attrs_13'} == 1) {
                   1232: 	    my $notes = &Apache::lonnet::metadata($filelink,'notes');
                   1233: 	    $r->print('<td> '.($notes eq '' ? '&nbsp;' : $notes).
                   1234: 		      " </td>\n");
                   1235: 	}
                   1236: 	
                   1237: 	if ($hash{'display_attrs_14'} == 1) {
                   1238: 	    my $abstract = &Apache::lonnet::metadata($filelink,'abstract');
                   1239: 	    $r->print('<td> '.($abstract eq '' ? '&nbsp;' : $abstract).
                   1240: 		      " </td>\n");
                   1241: 	}
                   1242: 	
1.193     jms      1243: 	if ($hash{'display_attrs_15'} == 1) {
                   1244: 	    my $gradelevel = &Apache::lonnet::metadata($filelink,'gradelevel');
                   1245: 	    $r->print('<td> '.($gradelevel eq '' ? '&nbsp;' : $gradelevel).
                   1246: 		      " </td>\n");
                   1247: 	}
                   1248: 	
1.195     jms      1249: 	if ($hash{'display_attrs_16'} == 1) {
                   1250: 	    my $standards = &Apache::lonnet::metadata($filelink,'standards');
                   1251: 	    $r->print('<td> '.($standards eq '' ? '&nbsp;' : $standards).
                   1252: 		      " </td>\n");
                   1253: 	}
                   1254: 	
1.185     jms      1255: 	$r->print(&Apache::loncommon::end_data_table_row());
                   1256: }
                   1257:     
                   1258:     
1.17      harris41 1259: 
1.2       harris41 1260: # -- display directory
1.1       www      1261:     if ($fnptr == $dirptr) {
1.2       harris41 1262: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41 1263: 	my $anchor = $curdir;
1.162     albertel 1264: 	$anchor =~ s/\W//g;
1.182     bisitz   1265: #SB	$r->print("<tr bgcolor=\"$fileclr\">$extrafield<td valign=$valign>");
                   1266:         $r->print(&Apache::loncommon::start_data_table_row()); # SB: bgcolor suggestion: darkgrey ("LC_info_row"?!?)
                   1267: #	$r->print('<tr class="LC_info_row">');
1.194     jms      1268:         $r->print($extrafield.'<td class="LC_middle LC_nobreak">');
1.2       harris41 1269: 	&begin_form ($r,$curdir);
1.4       harris41 1270: 	my $indentm1 = $indent-1;
1.194     jms      1271: 	my $count = 0;
                   1272: 	while ($count < $indentm1) {
1.199     droeschl 1273: 	    $r->print ('<img alt="" src="',$iconpath
                   1274: 	               ,'whitespace_21.gif" class="LC_icon" />');
1.194     jms      1275:             $count++;
1.1       www      1276: 	}
1.131     albertel 1277: 	$r->print ('<input type="hidden" name="acts" value="" />');
1.194     jms      1278: 	$r->print ('<a name="'.$anchor.'"></a>');
1.199     droeschl 1279:         $r->print ('<a href="#" onclick="document.dirpath'.($dnum-1).'.submit()"><img src="'.$iconpath.
1.194     jms      1280: 		   'arrow.'.($nowOpen ? "open" : "closed" ).'.gif"');
1.199     droeschl 1281: 	$r->print (' alt="'.$msg.'" class="LC_fileicon" /></a>'.
1.17      harris41 1282: 		   "\n");
1.128     foxr     1283: 	my $quotable_curdir = &Apache::loncommon::escape_single($curdir);
1.223     raeburn  1284:         my $quotable_startdir = &Apache::loncommon::escape_single($startdir);
                   1285:         my $quotable_listname = &Apache::loncommon::escape_single($listname);
                   1286: 
1.194     jms      1287:         my $location = &Apache::loncommon::lonhttpdurl("/adm/lonIcons");
                   1288: 	my $icon = "navmap.folder.".($nowOpen ? "open":"closed").'.gif';
1.204     raeburn  1289:         $r->print ('<a href="javascript:gothere('
                   1290:                   ."'$quotable_curdir'".');">'
                   1291:                   .'<img class="LC_fileicon" alt="'.&mt('Open Folder').'" src="'
                   1292:                   .$location.'/'.$icon.'" />'
                   1293:                   ."\n");
1.208     wenzelju 1294: 	$r->print ("$listname</a></form>");
                   1295: # Wishlistlink
                   1296:         $r->print('</td><td><a href="javascript:;" '.
1.214     raeburn  1297:                   'title="'.&mt('Save a link for this folder in Stored Links').'" '.
1.223     raeburn  1298:                   'onclick="set_wishlistlink('."'$listname','$quotable_startdir$quotable_listname"."/'".')">'.
1.208     wenzelju 1299:                   '<img class="LC_icon" src="/res/adm/pages/wishlist.png" '.
1.214     raeburn  1300:                   'alt="'.&mt('save in Stored Links').'" style="width:22px;"/></a></td>');
1.86      www      1301: # Attributes
                   1302: 	my $filelink = $startdir.$filecom[0].'/default';
                   1303: 
                   1304: 	if ($hash{'display_attrs_0'} == 1) {
1.169     albertel 1305: 	    my $title = &Apache::lonnet::gettitle($filelink);
1.86      www      1306: 	    $r->print('<td> '.($title eq '' ? '&nbsp;' : $title).
                   1307: 		      ' </td>'."\n");
                   1308: 	}
1.194     jms      1309: 	$r->print('<td class="LC_right"> ',
1.86      www      1310: 		  $filecom[8]," </td>\n") 
                   1311: 	    if $hash{'display_attrs_1'} == 1;
1.194     jms      1312: 	$r->print('<td class="LC_break"> '.
1.181     bisitz   1313:                   (&Apache::lonlocal::locallocaltime($filecom[9]))." </td>\n")
1.86      www      1314: 	    if $hash{'display_attrs_2'} == 1;
1.194     jms      1315: 	$r->print('<td class="LC_break"> '.
1.181     bisitz   1316:                   (&Apache::lonlocal::locallocaltime($filecom[10]))." </td>\n")
1.86      www      1317: 	    if $hash{'display_attrs_3'} == 1;
                   1318: 
                   1319: 	if ($hash{'display_attrs_4'} == 1) {
                   1320: 	    my $author = &Apache::lonnet::metadata($filelink,'author');
                   1321: 	    $r->print('<td> '.($author eq '' ? '&nbsp;' : $author).
                   1322: 		      " </td>\n");
                   1323: 	}
                   1324: 	if ($hash{'display_attrs_5'} == 1) {
                   1325: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
                   1326: 	    # $keywords = '&nbsp;' if (!$keywords);
                   1327: 	    $r->print('<td> '.($keywords eq '' ? '&nbsp;' : $keywords).
                   1328: 		      " </td>\n");
                   1329: 	}
                   1330: 	if ($hash{'display_attrs_6'} == 1) {
                   1331: 	    my $lang = &Apache::lonnet::metadata($filelink,'language');
                   1332: 	    $lang = &Apache::loncommon::languagedescription($lang);
                   1333: 	    $r->print('<td> '.($lang eq '' ? '&nbsp;' : $lang).
                   1334: 		      " </td>\n");
                   1335: 	}
1.185     jms      1336: 	
1.86      www      1337: 	if ($hash{'display_attrs_8'} == 1) {
                   1338: 	   $r->print('<td>&nbsp;</td>');
                   1339: 	}
1.115     www      1340:  	if ($hash{'display_attrs_10'} == 1) {
1.109     taceyjo1 1341: 	   $r->print('<td>&nbsp;</td>');
                   1342: 	}
1.185     jms      1343: 	if ($hash{'display_attrs_7'} == 1) {
                   1344: 	   $r->print('<td>&nbsp;</td>');
1.221     raeburn  1345:         }
                   1346:         if ($hash{'display_attrs_11'} == 1) {
1.111     www      1347: 	   $r->print('<td>&nbsp;</td>');
                   1348: 	}
1.185     jms      1349: 	if ($hash{'display_attrs_12'} == 1) {
                   1350: 	    my $subject = &Apache::lonnet::metadata($filelink,'subject');
                   1351: 	    $r->print('<td> '.($subject eq '' ? '&nbsp;' : $subject).
                   1352: 		      " </td>\n");
                   1353: 	}
1.186     jms      1354: 	if ($hash{'display_attrs_13'} == 1) {
                   1355: 	    my $notes = &Apache::lonnet::metadata($filelink,'notes');
                   1356: 	    $r->print('<td> '.($notes eq '' ? '&nbsp;' : $notes).
                   1357: 		      " </td>\n");
                   1358: 	}
                   1359: 	
                   1360: 	if ($hash{'display_attrs_14'} == 1) {
                   1361: 	    my $abstract = &Apache::lonnet::metadata($filelink,'abstract');
                   1362: 	    $r->print('<td> '.($abstract eq '' ? '&nbsp;' : $abstract).
                   1363: 		      " </td>\n");
                   1364: 	}
1.185     jms      1365: 	
1.193     jms      1366: 	if ($hash{'display_attrs_15'} == 1) {
                   1367: 	    my $gradelevel = &Apache::lonnet::metadata($filelink,'gradelevel');
                   1368: 	    $r->print('<td> '.($gradelevel eq '' ? '&nbsp;' : $gradelevel).
                   1369: 		      " </td>\n");
                   1370: 	}
                   1371: 	
1.195     jms      1372: 	if ($hash{'display_attrs_16'} == 1) {
                   1373: 	    my $standards = &Apache::lonnet::metadata($filelink,'standards');
                   1374: 	    $r->print('<td> '.($standards eq '' ? '&nbsp;' : $standards).
                   1375: 		      " </td>\n");
                   1376: 	}
                   1377: 	
                   1378: 	
1.185     jms      1379: 	$r->print(&Apache::loncommon::end_data_table_row());
1.1       www      1380:     }
1.2       harris41 1381: 
1.1       www      1382: }
                   1383: 
1.148     www      1384: sub coursecontext {
                   1385:     my ($r,$filelink)=@_;
                   1386:     my $filesymb=&Apache::lonnet::symbread($filelink);
                   1387:     if ($filesymb) {
                   1388: 	my ($map,$index,$resource)=&Apache::lonnet::decode_symb($filesymb);
1.219     bisitz   1389: 	$r->print(
                   1390:             &mt('Already in this course:').'<br />'
                   1391:            .&mt('[_1] in folder/map [_2]',
                   1392:                     &Apache::lonnet::gettitle($resource),
                   1393:                     &Apache::lonnet::gettitle($map))
                   1394:            .'<br />');
1.148     www      1395:     }
                   1396: }
                   1397: 
1.140     www      1398: sub showpreview {
                   1399:     my ($filelink)=@_;
1.218     raeburn  1400:     if ($filelink=~m-^(/ext/|https?://)-) {
1.150     www      1401: 	return &mt('External Resource, preview not enabled');
                   1402:     }
1.140     www      1403:     my ($curfext)=($filelink=~/\.(\w+)$/);
                   1404:     my $output='';
                   1405:     my $embstyle=&Apache::loncommon::fileembstyle($curfext);
                   1406:     if ($embstyle eq 'ssi') {
                   1407:        my $cache=$Apache::lonnet::perlvar{'lonDocRoot'}.$filelink.
                   1408:                     '.tmp';
                   1409:        if ((!$env{'form.updatedisplay'}) &&
                   1410:                     (-e $cache)) {
                   1411:           open(FH,$cache);
                   1412:           $output=join("\n",<FH>);
                   1413:           close(FH);
                   1414:        } else {
1.147     www      1415: # In update display mode, remove old cache. This is done to retroactively
                   1416: # clean up course context renderings.
                   1417: 	  if (-e $cache) {
                   1418: 	       unlink($cache);
                   1419: 	  }
1.140     www      1420:           $output=&Apache::lonnet::ssi_body($filelink);
1.146     www      1421: # Is access denied? Don't render, don't store
1.140     www      1422:           if ($output=~/LONCAPAACCESSCONTROLERRORSCREEN/s) {
                   1423:              $output='';
1.146     www      1424: # Was this rendered in course content? Don't store
                   1425:           } elsif (!&Apache::lonnet::symbread($filelink)) {
1.140     www      1426:              open(FH,">$cache");
                   1427:              print FH $output;
                   1428:              close(FH);
                   1429:           }
                   1430:        }
                   1431:     } elsif ($embstyle eq 'img') {
1.152     albertel 1432:        $output='<img alt="'.&mt('Preview').'" src="'.$filelink.'" />';
1.154     albertel 1433:     } elsif ($filelink=~m{^/res/($match_domain)/($match_username)/}) {
1.152     albertel 1434:        $output='<img  alt="'.&mt('Preview').'" src="http://'.
1.157     albertel 1435:                  &Apache::lonnet::hostname(&Apache::lonnet::homeserver($2,$1)).
1.140     www      1436:                  '/cgi-bin/thumbnail.gif?url='.$filelink.'" />';
                   1437:     }
                   1438:     return $output;
                   1439: }
                   1440: 
1.113     www      1441: sub dynmetaprint {
                   1442:     my ($r,$filelink,$item)=@_;
                   1443:     if ($dynhash{$filelink}->{$item}) {
1.114     www      1444: 	$r->print("\n<br />".$fieldnames{$item}.': '.
1.113     www      1445: 		  &Apache::lonmeta::prettyprint($item,
                   1446: 						$dynhash{$filelink}->{$item},
1.145     www      1447: 		  (($env{'form.catalogmode'} ne 'import')?'preview':''),
1.113     www      1448: 		  '',
1.145     www      1449: 		  (($env{'form.catalogmode'} eq 'import')?'document.forms.fileattr':''),1));
1.113     www      1450:     }
                   1451: }
                   1452: 
1.14      harris41 1453: # ------------------- prints the beginning of a form for directory or file link
1.1       www      1454: sub begin_form {
                   1455:     my ($r,$uri) = @_;
1.3       harris41 1456:     my $anchor = $uri;
1.162     albertel 1457:     $anchor =~ s/\W//g;
                   1458:     $uri=&Apache::loncommon::escape_single($uri);
1.17      harris41 1459:     $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
                   1460: 	       '#'.$anchor.
1.199     droeschl 1461: 	       '" onsubmit="return rep_dirpath(\''.$dnum.'\''.
1.17      harris41 1462: 	       ',document.forms.fileattr.acts.value)" '.
1.16      harris41 1463: 	       'enctype="application/x-www-form-urlencoded">'."\n");
1.131     albertel 1464:     $r->print ('<input type="hidden" name="openuri" value="'.$uri.'" />'.
1.17      harris41 1465: 	       "\n");
1.131     albertel 1466:     $r->print ('<input type="hidden" name="dirPointer" value="on" />'."\n");
1.170     albertel 1467:     $r->print(&Apache::loncommon::inhibit_menu_check('input'));
1.16      harris41 1468:     $dnum++;
1.17      harris41 1469: }
                   1470: 
                   1471: # --------- settings whenever the user causes the indexer window to be launched
                   1472: sub start_fresh_session {
1.149     albertel 1473:     my ($hash) = @_;
                   1474:     delete $hash->{'form.catalogmode'};
                   1475:     delete $hash->{'form.mode'};
                   1476:     delete $hash->{'form.form'};
                   1477:     delete $hash->{'form.element'};
                   1478:     delete $hash->{'form.omit'};
                   1479:     delete $hash->{'form.only'};
1.222     raeburn  1480:     foreach (keys(%{$hash})) {
1.149     albertel 1481:         delete $hash->{$_} if (/^(pre_|store)/);
1.27      harris41 1482:     }
1.1       www      1483: }
                   1484: 
1.35      matthew  1485: # ------------------------------------------------------------------- setvalues
                   1486: sub setvalues {
                   1487:     # setvalues is used in registerurl to synchronize the database
                   1488:     # hash and environment hashes
                   1489:     my ($H1,$h1key,$H2,$h2key) =@_;
                   1490:     #
                   1491:     if (exists $H2->{$h2key}) {
                   1492: 	$H1->{$h1key} = $H2->{$h2key};
                   1493:     } elsif (exists $H1->{$h1key}) {
                   1494: 	$H2->{$h2key} = $H1->{$h1key};
                   1495:     } 
                   1496: }
                   1497: 
1.1       www      1498: 1;
1.54      www      1499: 
                   1500: sub cleanup {
1.55      www      1501:     if (tied(%hash)){
                   1502: 	&Apache::lonnet::logthis('Cleanup indexer: hash');
                   1503:     }
1.138     albertel 1504:     return OK;
1.54      www      1505: }
1.23      harris41 1506: 
1.126     foxr     1507: 
                   1508: 
                   1509: 
                   1510: 
1.23      harris41 1511: =head1 NAME
                   1512: 
                   1513: Apache::lonindexer - mod_perl module for cross server filesystem browsing
                   1514: 
                   1515: =head1 SYNOPSIS
                   1516: 
                   1517: Invoked by /etc/httpd/conf/srm.conf:
                   1518: 
                   1519:  <LocationMatch "^/res.*/$">
                   1520:  SetHandler perl-script
                   1521:  PerlHandler Apache::lonindexer
                   1522:  </LocationMatch>
                   1523: 
                   1524: =head1 INTRODUCTION
                   1525: 
                   1526: This module enables a scheme of browsing across a cross server.
                   1527: 
                   1528: This is part of the LearningOnline Network with CAPA project
                   1529: described at http://www.lon-capa.org.
                   1530: 
                   1531: =head1 HANDLER SUBROUTINE
                   1532: 
                   1533: This routine is called by Apache and mod_perl.
                   1534: 
                   1535: =over 4
                   1536: 
                   1537: =item *
                   1538: 
                   1539: read in machine configuration variables
                   1540: 
                   1541: =item *
                   1542: 
                   1543: see if called from an interactive mode
                   1544: 
                   1545: =item *
                   1546: 
                   1547: refresh environment with user database values (in %hash)
                   1548: 
                   1549: =item *
                   1550: 
                   1551: define extra fields and buttons in case of special mode
                   1552: 
                   1553: =item *
                   1554: 
                   1555: set catalogmodefunctions to have extra needed javascript functionality
                   1556: 
                   1557: =item *
                   1558: 
                   1559: print header
                   1560: 
                   1561: =item *
                   1562: 
                   1563: evaluate actions from previous page (both cumulatively and chronologically)
                   1564: 
                   1565: =item *
                   1566: 
                   1567: output title
                   1568: 
                   1569: =item *
                   1570: 
                   1571: get state of file attributes to be showing
                   1572: 
                   1573: =item *
                   1574: 
                   1575: output state of file attributes to be showing
                   1576: 
                   1577: =item *
                   1578: 
                   1579: output starting row to the indexed file/directory hierarchy
                   1580: 
                   1581: =item *
                   1582: 
                   1583: read in what directories have previously been set to "open"
                   1584: 
                   1585: =item *
                   1586: 
                   1587: if not at top level, provide an uplink arrow
                   1588: 
                   1589: =item *
                   1590: 
                   1591: recursively go through all the directories and output as appropriate
                   1592: 
                   1593: =item *
                   1594: 
                   1595: information useful for group import
                   1596: 
                   1597: =item *
                   1598: 
                   1599: end the tables
                   1600: 
                   1601: =item *
                   1602: 
                   1603: end the output and return
                   1604: 
                   1605: =back
                   1606: 
                   1607: =head1 OTHER SUBROUTINES
                   1608: 
                   1609: =over 4
                   1610: 
                   1611: =item *
                   1612: 
                   1613: scanDir - recursive scan of a directory
                   1614: 
                   1615: =item *
                   1616: 
                   1617: get_list - get complete matched list based on the uri (returns an array)
                   1618: 
                   1619: =item *
                   1620: 
                   1621: match_ext - filters out files based on extensions (returns an array)
                   1622: 
                   1623: =item *
                   1624: 
                   1625: display_line - displays one line in appropriate table format
                   1626: 
                   1627: =item *
                   1628: 
                   1629: begin_form - prints the beginning of a form for directory or file link
                   1630: 
                   1631: =item *
                   1632: 
                   1633: start_fresh_session - settings whenever the user causes the indexer window
                   1634: to be launched
                   1635: 
                   1636: =back
                   1637: 
                   1638: =cut

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