File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.230: download - view: text, annotated - select for diffs
Thu Sep 3 15:38:51 2020 UTC (3 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- Improve readability in modal pop-up for .js, .css, .txt, and .tab files.

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

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