File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.17: download - view: text, annotated - select for diffs
Mon Aug 13 14:50:35 2001 UTC (22 years, 10 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
cleaning up code and enabling path into second phase (group sorting)

    1: # The LearningOnline Network with CAPA
    2: #
    3: # Directory Indexer
    4: #
    5: # YEAR=1999
    6: # 5/21/99, 5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
    7: # 11/23 Gerd Kortemeyer
    8: # YEAR=2000
    9: # 07/20-08/04 H.K. Ng
   10: # YEAR=2001
   11: # 05/9-05/19/2001 H. K. Ng
   12: # 05/21/2001 H. K. Ng
   13: # 05/23/2001 H. K. Ng
   14: # 5/31,6/1,6/2,6/15 Scott Harrison
   15: # 6/26,7/8 H. K. Ng
   16: # 8/6,8/7,8/10 Scott Harrison
   17: 
   18: package Apache::lonindexer;
   19: 
   20: use strict;
   21: use Apache::lonnet();
   22: use Apache::Constants qw(:common);
   23: use Apache::File;
   24: use GDBM_File;
   25: 
   26: my %hash; # tied to a user-specific gdbm file
   27: my %dirs; # keys are directories, values are the open/close status
   28: my %language; # has the reference information present in language.tab
   29: 
   30: # ----- Values which are set by the handler subroutine and are accessible to
   31: # -----     other methods.
   32: my $extrafield; # default extra table cell
   33: my $fnum; # file counter
   34: my $dnum; # directory counter
   35: 
   36: # ---------------------------------------------------------------------- BEGIN
   37: sub BEGIN {
   38:     my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
   39: 			     '/language.tab');
   40:     map {
   41: 	$_=~/(\w+)\s+([\w\s\-]+)/;
   42: 	$language{$1}=$2;
   43:     } <$fh>;
   44: }
   45: 
   46: # ---------------------------------------------------------------- Main Handler
   47: sub handler {
   48:     my $r = shift;
   49:     $r->content_type('text/html');
   50:     $r->send_http_header;
   51:     return OK if $r->header_only;
   52:     $fnum=0;
   53:     $dnum=0;
   54: 
   55: # --------------------------------------------- machine configuration variables
   56:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
   57:     my $domain  = $r->dir_config('lonDefDomain');
   58:     my $role    = $r->dir_config('lonRole');
   59:     my $loadlim = $r->dir_config('lonLoadLim');
   60:     my $servadm = $r->dir_config('lonAdmEMail');
   61:     my $sysadm  = $r->dir_config('lonSysEMail');
   62:     my $lonhost = $r->dir_config('lonHostID');
   63:     my $tabdir  = $r->dir_config('lonTabDir');
   64: 
   65:     my $fileclr='#ffffe6';
   66:     my $line;
   67:     my (@attrchk,@openpath);
   68:     my $uri=$r->uri;
   69: 
   70: # -------------------------------------- see if called from an interactive mode
   71:     &get_unprocessed_cgi();
   72: 
   73:     my $closebutton='';
   74:     my $groupimportbutton='';
   75:     my $colspan=''; 
   76: 
   77:     $extrafield='';
   78:     my $diropendb = 
   79: 	"/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
   80: 
   81:     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
   82: 	if ($ENV{'form.launch'} eq '1') {
   83: 	    &start_fresh_session();
   84: 	}
   85: 
   86: # -------------------- refresh environment with user database values (in %hash)
   87: 	if ($hash{'mode_catalog'} eq 'interactive') {
   88: 	    $ENV{'form.catalogmode'}='interactive';
   89: 	}
   90: 	if ($hash{'mode_catalog'} eq 'groupimport') {
   91: 	    $ENV{'form.catalogmode'}='groupimport';
   92: 	}
   93: 
   94: # --------------------- define extra fields and buttons in case of special mode
   95: 	if ($ENV{'form.catalogmode'} eq 'interactive') {
   96: 	    $hash{'mode_catalog'}='interactive';
   97: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
   98: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
   99: 		' border="0" /></td>';
  100: 	    $colspan=" colspan='2' ";
  101:             $closebutton=<<END;
  102: <input type="button" name="close" value='CLOSE' onClick="self.close()">
  103: END
  104:         }
  105: 	elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
  106: 	    $hash{'mode_catalog'}='groupimport';
  107: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
  108: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
  109: 		' border="0" /></td>';
  110: 	    $colspan=" colspan='2' ";
  111:             $closebutton=<<END;
  112: <input type="button" name="close" value='CLOSE' onClick="self.close()">
  113: END
  114:             $groupimportbutton=<<END;
  115: <input type="button" name="groupimport" value='GROUP IMPORT'
  116: onClick="javascript:select_group()">
  117: END
  118:         }
  119: 
  120: # ------ set catalogmodefunctions to have extra needed javascript functionality
  121: 	my $catalogmodefunctions='';
  122: 	if ($ENV{'form.catalogmode'} eq 'interactive' or
  123: 	    $ENV{'form.catalogmode'} eq 'groupimport') {
  124: 	    $catalogmodefunctions=<<END;
  125: function select_data(title,url) {
  126:     changeTitle(title);
  127:     changeURL(url);
  128:     self.close();
  129: }
  130: function select_group() {
  131:     window.location="/adm/groupsort?acts="+document.forms.fileattr.acts.value;
  132: }
  133: function changeTitle(val) {
  134:     if (opener.inf.document.forms.resinfo.elements.t) {
  135:         opener.inf.document.forms.resinfo.elements.t.value=val;
  136:     }
  137: }
  138: function changeURL(val) {
  139:     if (opener.inf.document.forms.resinfo.elements.u) {
  140: 	opener.inf.document.forms.resinfo.elements.u.value=val;
  141:     }
  142: }
  143: END
  144:         }
  145: 	if ($ENV{'form.catalogmode'} eq 'groupimport') {
  146: 	    $catalogmodefunctions.=<<END;
  147: var acts='';
  148: function queue(val) {
  149:     if (eval("document.forms."+val+".filelink.checked")) {
  150: 	var l=val.length;
  151: 	var v=val.substring(4,l);
  152: 	document.forms.fileattr.acts.value+='1a'+v+'b';
  153:     }
  154:     else {
  155: 	var l=val.length;
  156: 	var v=val.substring(4,l);
  157: 	document.forms.fileattr.acts.value+='0a'+v+'b';
  158:     }
  159: }
  160: function rep_dirpath(suffix,val) {
  161:     eval("document.forms.dirpath"+suffix+".acts.value=val");
  162: }
  163: END
  164: 	}
  165: 
  166: # ---------------------------------------------------------------- Print Header
  167: 	$r->print(<<ENDHEADER);
  168: <html>
  169: <head>
  170: <title>The LearningOnline Network With CAPA Directory Browser</title>
  171: 
  172: <script language="javascript">
  173: $catalogmodefunctions
  174: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
  175:     var options = "width=" + w + ",height=" + h + ",";
  176:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
  177:     options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
  178:     var newWin = window.open(url, wdwName, options);
  179:     newWin.focus();
  180: }
  181: function gothere(val) {
  182:     window.location=val+'?acts='+document.forms.fileattr.acts.value;
  183: }
  184: </script>
  185: 
  186: </head>
  187: <body bgcolor="#FFFFFF">
  188: ENDHEADER
  189: 
  190: # - Evaluate actions from previous page (both cumulatively and chronologically)
  191:         if ($ENV{'form.catalogmode'} eq 'groupimport') {
  192: 	    my $acts=$ENV{'form.acts'};
  193: 	    my @Acts=split(/b/,$acts);
  194: 	    my %ahash;
  195: 	    my %achash;
  196: 	    my $ac=0;
  197: 	    # some initial hashes for working with data
  198: 	    map {
  199: 		my ($state,$ref)=split(/a/);
  200: 		$ahash{$ref}=$state;
  201: 		$achash{$ref}=$ac;
  202: 		$ac++;
  203: 	    } (@Acts);
  204: 	    # sorting through the actions and changing the tied database hash
  205: 	    map {
  206: 		my $key=$_;
  207: 		if ($ahash{$key} eq '1') {
  208: 		    $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
  209: 			$hash{'pre_'.$key.'_title'};
  210: 		    $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
  211: 			$hash{'storectr'}+0;
  212: 		    $hash{'storectr'}++;
  213: 		}
  214: 		if ($ahash{$key} eq '0') {
  215: 		    if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
  216: 			delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
  217: 		    }
  218: 		}
  219: 	    } sort {$achash{$a}<=>$achash{$b}} (keys %ahash);
  220: 	    # deleting the previously cached listing
  221: 	    map {
  222: 		if ($_ =~ /^pre_/ && $_ =~/link$/) {
  223: 		    my $key = $_;
  224: 		    $key =~ s/^pre_//;
  225: 		    $key =~ s/_[^_]*$//;
  226: 		    delete $hash{'pre_'.$key.'_title'};
  227: 		    delete $hash{'pre_'.$key.'_link'};
  228: 		}
  229: 	    } keys %hash;
  230: 	}
  231: 	
  232: # output title
  233: 	$r->print('<h2><font color="#888888">The LearningOnline With CAPA '.
  234: 		  'Network Directory Browser</font></h2>'."\n");
  235: # get state of file attributes to be showing
  236: 	if ($ENV{'form.attrs'} ne "") {
  237: 	    for (my $i=0; $i<=5; $i++) {
  238: 		delete $hash{'display_attrs_'.$i};
  239: 		if ($ENV{'form.attr'.$i} == 1) {
  240: 		    $attrchk[$i] = "checked";
  241: 		    $hash{'display_attrs_'.$i} = 1;
  242: 		}
  243: 	    }
  244: 	} else {
  245: 	    for (my $i=0; $i<=5; $i++) {
  246: 		$attrchk[$i] = "checked" if $hash{'display_attrs_'.$i} == 1;
  247: 	    }
  248: 	}
  249: # output state of file attributes to be showing
  250: 	$r->print(<<END);
  251: <b><font color="#666666">Display file attributes</font></b><br />
  252: <form method="post" name="fileattr" action="$uri"
  253:  enctype="application/x-www-form-urlencoded">
  254: <table border=0><tr>
  255: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] /> Size</td>
  256: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> Last
  257:  access</td>
  258: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> Last
  259:  modified</td>
  260: </tr><tr>
  261: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> Author</td>
  262: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> Keywords</td>
  263: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> Language</td>
  264: </tr></table>
  265: <input type="hidden" name="dirPointer" value="on" />
  266: <input type="hidden" name="acts" value="" />
  267: <input type="submit" name="attrs" value="Review" />&nbsp;
  268: <input type="submit" name="attrs" value="Refresh" />
  269: $closebutton
  270: $groupimportbutton
  271: </form>
  272: END
  273: 
  274:     # output starting row to the indexed file/directory hierarchy
  275:         my $titleclr="#ddffff";
  276:         $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");
  277: 	$r->print("<table border=0><tr>\n");
  278: 	$r->print("<td $colspan bgcolor=$titleclr><b>Name</b></td>\n");
  279: 	$r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) ".
  280: 		  "</b></td>\n") if ($hash{'display_attrs_0'} == 1);
  281: 	$r->print("<td bgcolor=$titleclr><b>Last accessed</b></td>\n") 
  282: 	    if ($hash{'display_attrs_1'} == 1);
  283: 	$r->print("<td bgcolor=$titleclr><b>Last modified</b></td>\n")
  284: 	    if ($hash{'display_attrs_2'} == 1);
  285: 	$r->print("<td bgcolor=$titleclr><b>Author(s)</b></td>\n")
  286: 	    if ($hash{'display_attrs_3'} == 1);
  287: 	$r->print("<td bgcolor=$titleclr><b>Keywords</b></td>\n")
  288: 	    if ($hash{'display_attrs_4'} == 1);
  289: 	$r->print("<td bgcolor=$titleclr><b>Language</b></td>\n")
  290: 	    if ($hash{'display_attrs_5'} == 1);
  291: 	$r->print("</tr>");
  292: 
  293: 	# read in what directories have previously been set to "open"
  294: 	map {
  295: 	    if ($_ =~ /^diropen_status_/) {
  296: 		my $key = $_;
  297: 		$key =~ s/^diropen_status_//;
  298: 		$dirs{$key} = $hash{$_};
  299: 	    }
  300: 	} keys %hash;
  301: 
  302: 	if ($ENV{'form.openuri'}) {  # take care of review and refresh options
  303: 	    my $uri=$ENV{'form.openuri'};
  304: 	    if (exists($hash{'diropen_status_'.$uri})) {
  305: 		my $cursta = $hash{'diropen_status_'.$uri};
  306: 		$dirs{$uri} = 'open';
  307: 		$hash{'diropen_status_'.$uri} = 'open';
  308: 		if ($cursta eq 'open') {
  309: 		    $dirs{$uri} = 'closed';
  310: 		    $hash{'diropen_status_'.$uri} = 'closed';
  311: 		}
  312: 	    } else {
  313: 		$hash{'diropen_status_'.$uri} = 'open';
  314: 		$dirs{$uri} = 'open';
  315: 	    }
  316: 	}
  317: 	
  318: 	my $bredir = $ENV{'form.dirPointer'};
  319: 	my $toplevel;
  320: 	my $indent = 0;
  321: 	$uri = $uri.'/' if $uri !~ /.*\/$/;
  322: 
  323: 	if ($bredir ne "on") {
  324: 	    $hash{'top.level'} = $uri;
  325: 	    $toplevel = $uri;
  326: 
  327: 	} else {
  328: 	    $toplevel = $hash{'top.level'};
  329: 	}
  330: 
  331: 	# if not at top level, provide an uplink arrow
  332: 	if ($toplevel ne "/res/"){
  333: 	    my (@uri_com) = split(/\//,$uri);
  334: 	    pop @uri_com;
  335: 	    my $upone = join('/',@uri_com);
  336: 	    my @list = qw (0);
  337: 	    &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
  338: 	    $indent = 1;
  339: 	}
  340: 
  341: 	# recursively go through all the directories and output as appropriate
  342: 	&scanDir ($r,$toplevel,$indent,\%hash);
  343: 	
  344: 	# information useful for group import
  345: 	$r->print("<form name='fnum'>");
  346: 	$r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
  347: 
  348: 	# end the tables
  349: 	$r->print("</table>");
  350: 	$r->print("</td></tr></table>");
  351: 
  352: 	# end the output and return
  353: 	$r->print("</body></html>\n");
  354: 	untie(%hash);
  355:     } else {
  356: 	$r->print('<html><head></head><body>Unable to tie hash to db '.
  357: 		  'file</body></html>');
  358: 	return OK;
  359:     }
  360:     return OK;
  361: }
  362: 
  363: 
  364: # ----------------------------------------------- recursive scan of a directory
  365: sub scanDir {
  366:     my ($r,$startdir,$indent,$hashref)=@_;
  367:     my ($compuri,$curdir);
  368:     my $dirptr=16384;
  369:     $indent++;
  370: 
  371:     my %dupdirs = %dirs;
  372:     my @list=&get_list($r,$startdir);
  373:     foreach my $line (@list) {
  374: 	my ($strip,$dom,$foo,$testdir,$foo)=split(/\&/,$line,5); 
  375: 	next if $strip =~ /.*\.meta$/;
  376: 	if ($dom eq "domain") {
  377: 	    $compuri = join('',$strip,"/");  # dom list has /res/<domain name>
  378: 	    $curdir = $compuri;
  379: 	} else {
  380: 	    # user, dir & file have name only, i.e., w/o path
  381: 	    $compuri = join('',$startdir,$strip,"/");
  382: 	    $curdir = $startdir;
  383: 	}
  384: 	my $diropen = "closed";
  385: 	if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/)) {
  386: 	    while (my ($key,$val)= each %dupdirs) {
  387: 		if ($key eq $compuri and $val eq "open") {
  388: 		    $diropen = "opened";
  389: 		    delete $dupdirs{key},$dirs{$key};
  390: 		}
  391: 	    }
  392: 	}
  393: 	&display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
  394: 	&scanDir ($r,$compuri,$indent) if $diropen eq "opened";
  395:     }
  396:     $indent--;
  397: }
  398: 
  399: # --------------- get complete matched list based on the uri (returns an array)
  400: sub get_list {
  401:     my ($r,$uri)=@_;
  402:     my @list;
  403:     my $luri = $uri;
  404:     $luri =~ s/\//_/g;
  405: 
  406:     if ($ENV{'form.attrs'} eq "Refresh") {
  407: 	map {
  408: 	    delete $hash{$_} if ($_ =~ /^dirlist_files_/);
  409: 	    } keys %hash;
  410:     }
  411: 
  412:     if ($hash{'dirlist_files'.$luri}) {
  413: 	@list = split(/\n/,$hash{'dirlist_files_'.$luri});
  414:     } else {
  415: 	@list = &Apache::lonnet::dirlist($uri);
  416: 	$hash{'dirlist_files_'.$luri} = join('\n',@list);
  417:     }
  418:     return @list=&match_ext($r,@list);
  419: }
  420: 
  421: # -------------------- filters out files based on extensions (returns an array)
  422: sub match_ext {
  423:     my ($r,@packlist)=@_;
  424:     my @trimlist;
  425:     my $nextline;
  426:     my @fileext;
  427:     my $dirptr=16384;
  428: 
  429:     my $tabdir  = $r->dir_config('lonTabDir');
  430:     my $fn = $tabdir.'/filetypes.tab';
  431:     if (-e $fn) {
  432: 	my $FH=Apache::File->new($fn);
  433: 	my @content=<$FH>;
  434: 	foreach my $line (@content) {
  435: 	    (my $ext,my $foo) = split /\s+/,$line;
  436: 	    push @fileext,$ext;
  437: 	}
  438:     }
  439:     foreach my $line (@packlist) {
  440: 	chomp $line;
  441: 	$line =~ s/^\/home\/httpd\/html//;
  442: 	my @unpackline = split (/\&/,$line);
  443: 	next if ($unpackline[0] eq ".");
  444: 	next if ($unpackline[0] eq "..");
  445: 	my @filecom = split (/\./,$unpackline[0]);
  446: 	my $fext = pop(@filecom);
  447: 	my $fnptr = $unpackline[3]&$dirptr;
  448:  	if ($fnptr == 0 and $unpackline[3] ne "") {
  449: 	    foreach my $nextline (@fileext) {
  450: 		push @trimlist,$line if $nextline eq $fext;
  451: 	    }
  452: 	} else {
  453: 	    push @trimlist,$line;
  454: 	}
  455:     }
  456:     @trimlist = sort (@trimlist);
  457:     return @trimlist;
  458: }
  459: 
  460: # ------------------------------- displays one line in appropriate table format
  461: sub display_line{
  462:     my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
  463:     my (@pathfn, $fndir, $fnptr);
  464:     my $dirptr=16384;
  465:     my $fileclr="#ffffe6";
  466:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
  467: 
  468:     my @filecom = split (/\&/,$line);
  469:     my @pathcom = split (/\//,$filecom[0]);
  470:     my $listname = $pathcom[scalar(@pathcom)-1];
  471:     my $fnptr = $filecom[3]&$dirptr;
  472:     my $msg = 'View '.$filecom[0].' resources';
  473:     $msg = 'Close '.$filecom[0].' directory' if $diropen eq "opened";
  474: 
  475:     my $tabtag="</td>";
  476:     my $i=0;
  477: 
  478:     while ($i<=5) {
  479: 	$tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,">&nbsp;</td>")
  480: 	    if $hash{'display_attrs_'.$i} == 1;
  481: 	$i++;
  482:     }
  483: 
  484: # display uplink arrow
  485:     if ($filecom[1] eq "viewOneUp") {
  486: 	$r->print("<tr>$extrafield");
  487: 	$r->print("<td bgcolor=$fileclr valign=bottom>\n");
  488: 	$r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
  489: 		   '/" '.
  490: 		   'onSubmit="return rep_dirpath(\'UP\','.
  491: 		   'document.forms.fileattr.acts.value)" '.
  492: 		   'enctype="application/x-www-form-urlencoded"'.
  493:                    '>'."\n");
  494: 	$r->print ('<input type=hidden name=openuri value="'.
  495: 		   $startdir.'">'."\n");
  496: 	$r->print ('<input type="hidden" name="acts" value="">'."\n");
  497: 	$r->print ('<input src="'.$iconpath.'arrow_up.gif"');
  498: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  499: 		   "\n");
  500: 	$r->print("Up $tabtag</tr></form>\n");
  501: 	return OK;
  502:     }
  503: 
  504: # display domain
  505:     if ($filecom[1] eq "domain") {
  506: 	$r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
  507: 	    if ($ENV{'form.dirPointer'} eq "on");
  508: 	$r->print("<tr>$extrafield");
  509: 	$r->print("<td bgcolor=$fileclr valign=bottom>");
  510: 	&begin_form ($r,$filecom[0].'/');
  511: 	my $anchor = $filecom[0].'/';
  512: 	$anchor =~ s/\///g;
  513: 	$r->print ('<a name="'.$anchor.'">');
  514: 	$r->print ('<input type="hidden" name="acts" value="">');
  515: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.
  516: 		   $diropen.'.gif"'); 
  517: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  518: 		   "\n");
  519: 	$r->print ('<a href="javascript:gothere(\''.$filecom[0].
  520: 		   '/\')"><img src="'.$iconpath.'server.gif"');
  521: 	$r->print (' border="0" /></a>'."\n");
  522: 	$r->print("Domain - $listname $tabtag</tr></form>\n");
  523: 	return OK;
  524: 
  525: # display user directory
  526:     }
  527:     if ($filecom[1] eq "user") {
  528: 	$r->print("<tr>$extrafield");
  529: 	$r->print("<td bgcolor=$fileclr valign=bottom nowrap>\n");
  530: 	my $curdir = $startdir.$filecom[0].'/';
  531: 	my $anchor = $curdir;
  532: 	$anchor =~ s/\///g;
  533: 	&begin_form ($r,$curdir);
  534: 	$r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
  535: 		   'whitespace1.gif" border="0" />'."\n");
  536: 	$r->print ('<input type="hidden" name="acts" value="">');
  537: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
  538: 		   '.gif"'); 
  539: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  540: 		   "\n");
  541: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
  542: 		   $iconpath.'quill.gif border="0" name="'.$msg.
  543: 		   '" height="22" /></a>');
  544: 	$r->print ($listname.$tabtag.'</tr></form>'."\n");
  545: 	return OK;
  546:     }
  547: 
  548: # display file
  549:     if ($fnptr == 0 and $filecom[3] ne "") {
  550: 	my @file_ext = split (/\./,$listname);
  551: 	my $curfext = $file_ext[scalar(@file_ext)-1];
  552: 	my $filelink = $startdir.$filecom[0];
  553: 	$r->print("<tr><td nowrap valign='bottom' bgcolor=$fileclr>");
  554: 	my $metafile = grep /^$filecom[0]\.meta\&/, @list;
  555: 	my $title;
  556:         if ($ENV{'form.catalogmode'} eq 'interactive') {
  557: 	    $title=$listname;
  558: 	    $title = &Apache::lonnet::metadata($filelink,'title')
  559: 		if ($metafile == 1);
  560: 	    $title=$listname unless $title;
  561: 	    $r->print("<a href='javascript:select_data(\"",
  562: 	              $title,'","',$filelink,"\")'>");
  563: 	    $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
  564: 		      "\n");
  565: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
  566: 	}
  567:         elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
  568: 	    $title=$listname;
  569: 	    $title = &Apache::lonnet::metadata($filelink,'title')
  570: 		if ($metafile == 1);
  571: 	    $title=$listname unless $title;
  572: 	    $r->print("<form name='form$fnum'>\n");
  573: 	    $r->print("<input type='checkbox' name='filelink"."' ".
  574: 		      "value='$filelink' onClick='".
  575: 		      "javascript:queue(\"form$fnum\")' ");
  576: 	    if ($hash{'store_'.$filelink}) {
  577: 		$r->print("checked");
  578: 	    }
  579: 	    $r->print(">\n");
  580: 	    $r->print("<input type='hidden' name='title"."' ".
  581: 		      "value='$title'>\n");
  582: 	    $r->print("</form>\n");
  583: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
  584: 	    $hash{"pre_${fnum}_link"}=$filelink;
  585: 	    $hash{"pre_${fnum}_title"}=$title;
  586:   	    $fnum++;
  587: 	}
  588: 
  589: 	if ($indent > 0 and $indent < 11) {
  590: 	    $r->print("<img src=",$iconpath,"whitespace",$indent,
  591: 		      ".gif border='0' />\n");
  592: 	} elsif ($indent >0) {
  593: 	    my $ten = int($indent/10.);
  594: 	    my $rem = $indent%10.0;
  595: 	    my $count = 0;
  596: 	    while ($count < $ten) {
  597: 		$r->print("<img src=",$iconpath,
  598: 			  "whitespace10.gif border='0' />\n");
  599: 	    $count++;
  600: 	    }
  601: 	    $r->print("<img src=",$iconpath,"whitespace",$rem,
  602: 		      ".gif border='0' />\n") if $rem > 0;
  603: 	}
  604: 
  605: 	$r->print("<img src=$iconpath$curfext.gif border='0' />\n");
  606: 	$r->print (" <a href=\"javascript:openWindow('".$filelink.
  607: 		   "', 'metadatafile', '450', '500', 'no', 'yes')\";".
  608: 		   " TARGET=_self>$listname</a> ");
  609: 
  610: 	$r->print (" (<a href=\"javascript:openWindow('".$filelink.
  611: 		   ".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; ".
  612: 		   "TARGET=_self>metadata</a>) ") if ($metafile == 1);
  613: 
  614: 	$r->print("</td>\n");
  615: 	$r->print("<td bgcolor=$fileclr align=right valign=bottom> ",
  616: 		  $filecom[8]," </td>\n") 
  617: 	    if $hash{'display_attrs_0'} == 1;
  618: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".
  619: 		  (localtime($filecom[9]))." </td>\n") 
  620: 	    if $hash{'display_attrs_1'} == 1;
  621: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".
  622: 		  (localtime($filecom[10]))." </td>\n") 
  623: 	    if $hash{'display_attrs_2'} == 1;
  624: 
  625: 	if ($hash{'display_attrs_3'} == 1) {
  626: 	    my $author = &Apache::lonnet::metadata($filelink,'author')
  627: 		if ($metafile == 1);
  628: 	    $author = '&nbsp;' if (!$author);
  629: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$author.
  630: 		      " </td>\n");
  631: 	}
  632: 	if ($hash{'display_attrs_4'} == 1) {
  633: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
  634: 		if ($metafile == 1);
  635: 	    $keywords = '&nbsp;' if (!$keywords);
  636: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$keywords.
  637: 		      " </td>\n");
  638: 	}
  639: 	if ($hash{'display_attrs_5'} == 1) {
  640: 	    my $lang = &Apache::lonnet::metadata($filelink,'language')
  641: 		if ($metafile == 1);
  642: 	    $lang = $language{$lang};
  643: 	    $lang = '&nbsp;' if (!$lang);
  644: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$lang.
  645: 		      " </td>\n");
  646: 	}
  647: 	$r->print("</tr>\n");
  648:     }
  649: 
  650: # -- display directory
  651:     if ($fnptr == $dirptr) {
  652: 	my @file_ext = split (/\./,$listname);
  653: 	my $curfext = $file_ext[scalar(@file_ext)-1];
  654: 	my $curdir = $startdir.$filecom[0].'/';
  655: 	my $anchor = $curdir;
  656: 	$anchor =~ s/\///g;
  657: 	$r->print("<tr>$extrafield<td bgcolor=$fileclr valign=bottom>");
  658: 	&begin_form ($r,$curdir);
  659: 	my $indentm1 = $indent-1;
  660: 	if ($indentm1 < 11 and $indentm1 > 0) {
  661: 	    $r->print("<img src=",$iconpath,"whitespace",$indentm1,
  662: 		      ".gif border='0' />\n");
  663: 	} else {
  664: 	    my $ten = int($indentm1/10.);
  665: 	    my $rem = $indentm1%10.0;
  666: 	    my $count = 0;
  667: 	    while ($count < $ten) {
  668: 		$r->print ("<img src=",$iconpath
  669: 			   ,"whitespace10.gif border='0' />\n");
  670: 		$count++;
  671: 	    }
  672: 	    $r->print ("<img src=",$iconpath,"whitespace",$rem,
  673: 		       ".gif border='0' />\n") if $rem > 0;
  674: 	}
  675: 	$r->print ('<input type="hidden" name="acts" value="">');
  676: 	$r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
  677: 		   'folder_pointer_'.$diropen.'.gif"');
  678: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
  679: 		   "\n");
  680: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
  681: 		   $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
  682: 		   "\n");
  683: 	$r->print ("$listname$tabtag</tr></form>\n");
  684:     }
  685: 
  686: }
  687: 
  688: # ------------------- prints the beginning of a form for directory or file link
  689: sub begin_form {
  690:     my ($r,$uri) = @_;
  691:     my $anchor = $uri;
  692:     $anchor =~ s/\///g;
  693:     $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
  694: 	       '#'.$anchor.
  695: 	       '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
  696: 	       ',document.forms.fileattr.acts.value)" '.
  697: 	       'enctype="application/x-www-form-urlencoded">'."\n");
  698:     $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
  699: 	       "\n");
  700:     $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
  701:     $dnum++;
  702: }
  703: 
  704: # ----------- grab unprocessed CGI variables that may have been appended to URL
  705: sub get_unprocessed_cgi {
  706:     map {
  707:        my ($name, $value) = split(/=/,$_);
  708:        $value =~ tr/+/ /;
  709:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
  710:        if ($name eq 'catalogmode' or $name eq 'launch' or $name eq 'acts') {
  711:            $ENV{'form.'.$name}=$value;
  712:        }
  713:     } (split(/&/,$ENV{'QUERY_STRING'}));
  714: }
  715: 
  716: # --------- settings whenever the user causes the indexer window to be launched
  717: sub start_fresh_session {
  718:     delete $hash{'mode_catalog'};
  719:     map {
  720: 	if ($_ =~ /^pre_/) {
  721: 	    delete $hash{$_};
  722: 	}
  723: 	if ($_ =~ /^store/) {
  724: 	    delete $hash{$_};
  725: 	}
  726:     } keys %hash;    
  727: }
  728: 
  729: 1;
  730: __END__

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