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

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

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