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

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

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