File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.15: download - view: text, annotated - select for diffs
Tue Aug 7 15:14:51 2001 UTC (22 years, 11 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
catalog mode is now persistent and freshly instantiated

    1: # The LearningOnline Network with CAPA
    2: #
    3: # Directory Indexer
    4: # (Login Screen
    5: #
    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: # 07/20-08/04 H.K. Ng
    9: #
   10: # 05/9-05/19/2001 H. K. Ng
   11: # 05/21/2001 H. K. Ng
   12: # 05/23/2001 H. K. Ng
   13: # 05/31/2001 Scott Harrison
   14: # 06/01/2001 Scott Harrison
   15: # 06/02/2001 Scott Harrison
   16: # 06/15/2001 Scott Harrison
   17: # 06/26/2001 H. K. Ng
   18: # 07/08/2001 H. K. Ng
   19: 
   20: package Apache::lonindexer;
   21: 
   22: use strict;
   23: use Apache::lonnet();
   24: use Apache::Constants qw(:common);
   25: use Apache::File;
   26: use GDBM_File;
   27: 
   28: my %hash;
   29: my %dirs;
   30: my %language;
   31: my $hidden;
   32: my $extrafield;
   33: my $fnum;
   34: sub BEGIN {
   35:     my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
   36: 			     '/language.tab');
   37:     map {
   38: 	$_=~/(\w+)\s+([\w\s\-]+)/;
   39: 	$language{$1}=$2;
   40:     } <$fh>;
   41: }
   42: 
   43: sub handler {
   44:     my $r = shift;
   45:     $r->content_type('text/html');
   46:     $r->send_http_header;
   47:     return OK if $r->header_only;
   48:     $fnum=0;
   49:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
   50:     my $domain  = $r->dir_config('lonDefDomain');
   51:     my $role    = $r->dir_config('lonRole');
   52:     my $loadlim = $r->dir_config('lonLoadLim');
   53:     my $servadm = $r->dir_config('lonAdmEMail');
   54:     my $sysadm  = $r->dir_config('lonSysEMail');
   55:     my $lonhost = $r->dir_config('lonHostID');
   56:     my $tabdir  = $r->dir_config('lonTabDir');
   57: 
   58:     my $fileclr='#ffffe6';
   59:     my $line;
   60:     my (@attrchk,@openpath);
   61:     my $uri=$r->uri;
   62: 
   63: # -------------------------------------- see if called from an interactive mode
   64:     map {
   65:        my ($name, $value) = split(/=/,$_);
   66:        $value =~ tr/+/ /;
   67:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
   68:        if ($name eq 'catalogmode') {
   69:            $ENV{'form.'.$name}=$value;
   70:        }
   71:        if ($name eq 'launch') {
   72:            $ENV{'form.'.$name}=$value;
   73:        }
   74:     } (split(/&/,$ENV{'QUERY_STRING'}));
   75: 
   76:     $hidden=''; my $closebutton='';
   77:     my $groupimportbutton='';
   78:     my $colspan=''; 
   79: 
   80:     $extrafield='';
   81:     my $diropendb = "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
   82: 
   83:     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
   84: 	if ($ENV{'form.launch'} eq '1') {
   85: 	    delete $hash{'mode_catalog'};
   86: 	}
   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: 	if ($ENV{'form.catalogmode'} eq 'interactive') {
   95: 	    $hash{'mode_catalog'}='interactive';
   96: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
   97: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
   98: 		' border="0"></td>';
   99: 	    $colspan=" colspan='2' ";
  100: 	    $hidden=<<END;
  101: <input type='hidden' name='catalogmode' value='interactive'>
  102: END
  103:             $closebutton=<<END;
  104: <input type="button" name="close" value='CLOSE' onClick="self.close()">
  105: END
  106:          }
  107: 	elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
  108: 	    $hash{'mode_catalog'}='groupimport';
  109: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
  110: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
  111: 		' border="0"></td>';
  112: 	    $colspan=" colspan='2' ";
  113: 	    $hidden=<<END;
  114: <input type='hidden' name='catalogmode' value='groupimport'>
  115: END
  116:             $closebutton=<<END;
  117: <input type="button" name="close" value='CLOSE' onClick="self.close()">
  118: END
  119:             $groupimportbutton=<<END;
  120: <input type="button" name="groupimport" value='GROUP IMPORT' onClick="javascript:select_group()">
  121: END
  122:         }
  123: 
  124: 	my $catalogmodefunctions='';
  125: 	if ($ENV{'form.catalogmode'} eq 'interactive' or
  126: 	    $ENV{'form.catalogmode'} eq 'groupimport') {
  127: 	    $catalogmodefunctions=<<END;
  128: function select_data(title,url) {
  129:     changeTitle(title);
  130:     changeURL(url);
  131:     self.close();
  132: }
  133: function save_group() {
  134:     for (var num=0; num<document.forms.fnum.fnum.value; num++) {
  135: 	if (eval("document.forms.form"+num+".filelink.checked")) {
  136: 	    alert(eval("document.forms.form"+num+".title.value")+
  137: 		       eval("document.forms.form"+num+".filelink.value"));
  138: 	}
  139:     }
  140: }
  141: function select_group() {
  142:     var linkflag=false;
  143:     for (var num=0; num<document.forms.fnum.fnum.value; num++) {
  144: 	if (eval("document.forms.form"+num+".filelink.checked")) {
  145: //	    alert(eval("document.forms.form"+num+".title.value")+
  146: //		       eval("document.forms.form"+num+".filelink.value"));
  147: 	    insertRowInLastRow();
  148: 	    placeResourceInLastRow(
  149: 		   eval("document.forms.form"+num+".title.value"),
  150: 		   eval("document.forms.form"+num+".filelink.value"),
  151: 		   linkflag
  152: 				   );
  153: 	    linkflag=true;
  154: 	}
  155:     }
  156:     opener.editmode=0;
  157:     opener.notclear=0;
  158:     opener.linkmode=0;
  159:     opener.infoclear();
  160:     opener.draw();
  161: }
  162: function insertRowInLastRow() {
  163:     opener.insertrow(opener.maxrow);
  164:     opener.addobj(opener.maxrow,'e&2');
  165: }
  166: function placeResourceInLastRow (title,url,linkflag) {
  167:     opener.newresource(opener.maxrow,2,opener.escape(title),opener.escape(url),'false','normal');
  168:     opener.save();
  169:     opener.mostrecent=opener.obj.length-1;
  170:     if (linkflag) {
  171: 	opener.joinres(opener.linkmode,opener.mostrecent,0);
  172:     }
  173:     opener.linkmode=opener.mostrecent;
  174: }
  175: function changeTitle(val) {
  176:     if (opener.inf.document.forms.resinfo.elements.t) {
  177:         opener.inf.document.forms.resinfo.elements.t.value=val;
  178:     }
  179: }
  180: function changeURL(val) {
  181:     if (opener.inf.document.forms.resinfo.elements.u) {
  182: 	opener.inf.document.forms.resinfo.elements.u.value=val;
  183:     }
  184: }
  185: END
  186:         }
  187: 
  188: # ---------------------------------------------------------------- Print Header
  189: 	$r->print(<<ENDHEADER);
  190: <html>
  191: <head>
  192: <title>The LearningOnline Network With CAPA Directory Browser</title>
  193: 
  194: <script language="javascript">
  195: $catalogmodefunctions
  196: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
  197:     var options = "width=" + w + ",height=" + h + ",";
  198:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
  199:     options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
  200:     var newWin = window.open(url, wdwName, options);
  201:     newWin.focus();
  202: }
  203: </script>
  204: 
  205: </head>
  206: <body bgcolor="#FFFFFF">
  207: ENDHEADER
  208: 
  209: 	$r->print('<h2><font color="#888888">The LearningOnline With CAPA Network Directory Browser</font></h2>'."\n");
  210:     }
  211:     else {
  212: 	$r->print('<html><head></head><body>Unable to tie hash to db file</body></html>');
  213: 	return OK;
  214:     }
  215:     untie %hash;
  216:     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
  217: 
  218: 	if ($ENV{'form.attrs'} ne "") {
  219: 	    for (my $i=0; $i<=5; $i++) {
  220: 		delete $hash{'display_attrs_'.$i};
  221: 		if ($ENV{'form.attr'.$i} == 1) {
  222: 		    $attrchk[$i] = "checked";
  223: 		    $hash{'display_attrs_'.$i} = 1;
  224: 		}
  225: 	    }
  226: 	} else {
  227: 	    for (my $i=0; $i<=5; $i++) {
  228: 		$attrchk[$i] = "checked" if $hash{'display_attrs_'.$i} == 1;
  229: 	    }
  230: 	}
  231: 	$r->print(<<END);
  232: <b><font color="#666666">Display file attributes</font></b><br>
  233: <form method="post" name="fileattr" action="$uri" enctype="application/x-www-form-urlencoded">
  234: <table border=0><tr>
  235: <td><input type=checkbox name=attr0 value="1" $attrchk[0]> Size</td>
  236: <td><input type=checkbox name=attr1 value="1" $attrchk[1]> Last access</td>
  237: <td><input type=checkbox name=attr2 value="1" $attrchk[2]> Last modified</td>
  238: </tr><tr>
  239: <td><input type=checkbox name=attr3 value="1" $attrchk[3]> Author</td>
  240: <td><input type=checkbox name=attr4 value="1" $attrchk[4]> Keywords</td>
  241: <td><input type=checkbox name=attr5 value="1" $attrchk[5]> Language</td>
  242: </tr></table>
  243: <input type=hidden name=dirPointer value="on">
  244: <input type="submit" name="attrs" value="Review">&nbsp;
  245: <input type="submit" name="attrs" value="Refresh">
  246: $hidden
  247: $closebutton
  248: $groupimportbutton
  249: </form>
  250: END
  251: 
  252:         my $titleclr="#ddffff";
  253:         $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");
  254: 	$r->print("<table border=0><tr>\n");
  255: 	$r->print("<td $colspan bgcolor=$titleclr><b>Name</b></td>\n");
  256: 	$r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) </b></td>\n") if ($hash{'display_attrs_0'} == 1);
  257: 	$r->print("<td bgcolor=$titleclr><b>Last accessed</b></td>\n") if ($hash{'display_attrs_1'} == 1);
  258: 	$r->print("<td bgcolor=$titleclr><b>Last modified</b></td>\n") if ($hash{'display_attrs_2'} == 1);
  259: 	$r->print("<td bgcolor=$titleclr><b>Author(s)</b></td>\n") if ($hash{'display_attrs_3'} == 1);
  260: 	$r->print("<td bgcolor=$titleclr><b>Keywords</b></td>\n") if ($hash{'display_attrs_4'} == 1);
  261: 	$r->print("<td bgcolor=$titleclr><b>Language</b></td>\n") if ($hash{'display_attrs_5'} == 1);
  262: 	$r->print("</tr>");
  263: 
  264: 	map {
  265: 	    if ($_ =~ /^diropen_status_/) {
  266: 		my $key = $_;
  267: 		$key =~ s/^diropen_status_//;
  268: 		$dirs{$key} = $hash{$_};
  269: 	    }
  270: 	} keys %hash;
  271: 
  272: 	if ($ENV{'form.openuri'}) {  # take care of review and refresh options
  273: 	    my $uri=$ENV{'form.openuri'};
  274: 	    if (exists($hash{'diropen_status_'.$uri})) {
  275: 		my $cursta = $hash{'diropen_status_'.$uri};
  276: 		$dirs{$uri} = 'open';
  277: 		$hash{'diropen_status_'.$uri} = 'open';
  278: 		if ($cursta eq 'open') {
  279: 		    $dirs{$uri} = 'closed';
  280: 		    $hash{'diropen_status_'.$uri} = 'closed';
  281: 		}
  282: 	    } else {
  283: 		$hash{'diropen_status_'.$uri} = 'open';
  284: 		$dirs{$uri} = 'open';
  285: 	    }
  286: 	}
  287: 	
  288: 	my $bredir = $ENV{'form.dirPointer'};
  289: 	my $toplevel;
  290: 	my $indent = 0;
  291: 	$uri = $uri.'/' if $uri !~ /.*\/$/;
  292: 	if ($bredir ne "on") {
  293: 	    $hash{'top.level'} = $uri;
  294: 	    $toplevel = $uri;
  295: 
  296: 	} else {
  297: 	    $toplevel = $hash{'top.level'};
  298: 	}
  299: 	if ($toplevel ne "/res/"){
  300: 	    my (@uri_com) = split(/\//,$uri);
  301: 	    pop @uri_com;
  302: 	    my $upone = join('/',@uri_com);
  303: 	    my @list = qw (0);
  304: 	    &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
  305: 	    $indent = 1;
  306: 	}
  307: 	&scanDir ($r,$toplevel,$indent);
  308: 	
  309: 	$r->print("<form name='fnum'>");
  310: 	$r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
  311: 	$r->print("</table>");
  312: 	$r->print("</td></tr></table>");
  313: 	$r->print("</body></html>\n");
  314: 	untie(%hash);
  315:     } else {
  316: 	$r->print("Unable to tie hash to db file");
  317:     }
  318:     return OK;
  319: }
  320: 
  321: 
  322: # --------------------recursive scan of a directory
  323: sub scanDir {
  324:     my ($r,$startdir,$indent)=@_;
  325:     my ($compuri,$curdir);
  326:     my $dirptr=16384;
  327:     $indent++;
  328: 
  329:     my %dupdirs = %dirs;
  330:     my @list=&get_list($r,$startdir);
  331:     foreach my $line (@list) {
  332: 	my ($strip,$dom,$foo,$testdir,$foo)=split(/\&/,$line,5); 
  333: 	next if $strip =~ /.*\.meta$/;
  334: 	if ($dom eq "domain") {
  335: 	    $compuri = join('',$strip,"/");  # domain list has /res/<domain name>
  336: 	    $curdir = $compuri;
  337: 	} else {
  338: 	    $compuri = join('',$startdir,$strip,"/"); # user, dir & file have name only, i.e., w/o path
  339: 	    $curdir = $startdir;
  340: 	}
  341: 	my $diropen = "closed";
  342: 	if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/)) {
  343: 	    while (my ($key,$val)= each %dupdirs) {
  344: 		if ($key eq $compuri and $val eq "open") {
  345: 		    $diropen = "opened";
  346: 		    delete $dupdirs{key},$dirs{$key};
  347: 		}
  348: 	    }
  349: 	}
  350: 	&display_line($r,$diropen,$line,$indent,$curdir,@list);
  351: 	&scanDir ($r,$compuri,$indent) if $diropen eq "opened";
  352:     }
  353:     $indent--;
  354: }
  355: 
  356: # ----------------- get complete matched list based on the uri ------
  357: sub get_list {
  358:     my ($r,$uri)=@_;
  359:     my @list;
  360:     my $luri = $uri;
  361:     $luri =~ s/\//_/g;
  362: 
  363:     if ($ENV{'form.attrs'} eq "Refresh") {
  364: 	map {
  365: 	    delete $hash{$_} if ($_ =~ /^dirlist_files_/);
  366: 	    } keys %hash;
  367:     }
  368: 
  369:     if ($hash{'dirlist_files'.$luri}) {
  370: 	@list = split(/\n/,$hash{'dirlist_files_'.$luri});
  371:     } else {
  372: 	@list = &Apache::lonnet::dirlist($uri);
  373: 	$hash{'dirlist_files_'.$luri} = join('\n',@list);
  374:     }
  375:     return @list=&match_ext($r,@list);
  376: }
  377: 
  378: #-------------------------- filters out files based on extensions
  379: sub match_ext {
  380:     my ($r,@packlist)=@_;
  381:     my @trimlist;
  382:     my $nextline;
  383:     my @fileext;
  384:     my $dirptr=16384;
  385: 
  386:     my $tabdir  = $r->dir_config('lonTabDir');
  387:     my $fn = $tabdir.'/filetypes.tab';
  388:     if (-e $fn) {
  389: 	my $FH=Apache::File->new($fn);
  390: 	my @content=<$FH>;
  391: 	foreach my $line (@content) {
  392: 	    (my $ext,my $foo) = split /\s+/,$line;
  393: 	    push @fileext,$ext;
  394: 	}
  395:     }
  396:     foreach my $line (@packlist) {
  397: 	chomp $line;
  398: 	$line =~ s/^\/home\/httpd\/html//;
  399: 	my @unpackline = split (/\&/,$line);
  400: 	next if ($unpackline[0] eq ".");
  401: 	next if ($unpackline[0] eq "..");
  402: 	my @filecom = split (/\./,$unpackline[0]);
  403: 	my $fext = pop(@filecom);
  404: 	my $fnptr = $unpackline[3]&$dirptr;
  405:  	if ($fnptr == 0 and $unpackline[3] ne "") {
  406: 	    foreach my $nextline (@fileext) {
  407: 		push @trimlist,$line if $nextline eq $fext;
  408: 	    }
  409: 	} else {
  410: 	    push @trimlist,$line;
  411: 	}
  412:     }
  413:     @trimlist = sort (@trimlist);
  414:     return @trimlist;
  415: }
  416: 
  417: #------------------- displays one line in appropriate table format
  418: sub display_line{
  419:     my ($r,$diropen,$line,$indent,$startdir,@list)=@_;
  420:     my (@pathfn, $fndir, $fnptr);
  421:     my $dirptr=16384;
  422:     my $fileclr="#ffffe6";
  423:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
  424: 
  425:     my @filecom = split (/\&/,$line);
  426:     my @pathcom = split (/\//,$filecom[0]);
  427:     my $listname = $pathcom[scalar(@pathcom)-1];
  428:     my $fnptr = $filecom[3]&$dirptr;
  429:     my $msg = 'View '.$filecom[0].' resources';
  430:     $msg = 'Close '.$filecom[0].' directory' if $diropen eq "opened";
  431: 
  432:     my $tabtag="</td>";
  433:     my $i=0;
  434: 
  435:     while ($i<=5) {
  436: 	$tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,">&nbsp;</td>") if $hash{'display_attrs_'.$i} == 1;
  437: 	$i++;
  438:     }
  439:     if ($filecom[1] eq "viewOneUp") {
  440: 	$r->print("<tr>$extrafield");
  441: 	$r->print("<td bgcolor=$fileclr valign=bottom>\n");
  442: 	$r->print ('<form method="post" name="dirpath" action="'.$startdir.
  443: 		   '" enctype="application/x-www-form-urlencoded">'."\n");
  444: 	$r->print ($hidden.'<input type=hidden name=openuri value="'.$startdir.'">'."\n");
  445: 	$r->print ('<input src="'.$iconpath.'arrow_up.gif"');
  446: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'."\n");
  447: 	$r->print("Up $tabtag</tr></form>\n");
  448: 	return OK;
  449:     }
  450:     if ($filecom[1] eq "domain") {
  451: 	$r->print ('<input type=hidden name=dirPointer value="on">'."\n") if ($ENV{'form.dirPointer'} eq "on");
  452: 	$r->print("<tr>$extrafield");
  453: 	$r->print("<td bgcolor=$fileclr valign=bottom>");
  454: 	&begin_form ($r,$filecom[0].'/');
  455: 	my $anchor = $filecom[0].'/';
  456: 	$anchor =~ s/\///g;
  457: 	$r->print ('<a name="'.$anchor.'">');
  458: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.'.gif"'); 
  459: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'."\n");
  460: 	$r->print ('<a href="'.$filecom[0].'"><img src="'.$iconpath.'server.gif"');
  461: 	$r->print (' border="0"></a>'."\n");
  462: 	$r->print("Domain - $listname $tabtag</tr></form>\n");
  463: 	return OK;
  464:     }
  465:     if ($filecom[1] eq "user") {
  466: 	$r->print("<tr>$extrafield");
  467: 	$r->print("<td bgcolor=$fileclr valign=bottom nowrap>\n");
  468: 	my $curdir = $startdir.$filecom[0].'/';
  469: 	my $anchor = $curdir;
  470: 	$anchor =~ s/\///g;
  471: 	&begin_form ($r,$curdir);
  472: 	$r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.'whitespace1.gif" border=0>'."\n");
  473: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.'.gif"'); 
  474: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'."\n");
  475: 	$r->print ('<a href="'.$curdir.'"><img src='.$iconpath.'quill.gif border=0 name="'.$msg.'" height="22"></a>');
  476: 	$r->print ($listname.$tabtag.'</tr></form>'."\n");
  477: 	return OK;
  478:     }
  479: # display file
  480:     if ($fnptr == 0 and $filecom[3] ne "") {
  481: 	my @file_ext = split (/\./,$listname);
  482: 	my $curfext = $file_ext[scalar(@file_ext)-1];
  483: 	my $filelink = $startdir.$filecom[0];
  484: 	$r->print("<tr><td nowrap valign='bottom' bgcolor=$fileclr>");
  485: 	my $metafile = grep /^$filecom[0]\.meta\&/, @list;
  486: 	my $title;
  487:         if ($ENV{'form.catalogmode'} eq 'interactive') {
  488: 	    $title=$listname;
  489: 	    $title = &Apache::lonnet::metadata($filelink,'title')
  490: 		if ($metafile == 1);
  491: 	    $title=$listname unless $title;
  492: 	    $r->print("<a href='javascript:select_data(\"",
  493: 	              $title,'","',$filelink,"\")'>");
  494: 	    $r->print("<img src='",$iconpath,"select.gif' border=0></a>\n");
  495: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
  496: 	}
  497:         elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
  498: 	    $title=$listname;
  499: 	    $title = &Apache::lonnet::metadata($filelink,'title')
  500: 		if ($metafile == 1);
  501: 	    $title=$listname unless $title;
  502: 	    $r->print("<form name='form$fnum'>\n");
  503: 	    $r->print("<input type='checkbox' name='filelink"."' ".
  504: 		      "value='$filelink'>\n");
  505: 	    $r->print("<input type='hidden' name='title"."' ".
  506: 		      "value='$title'>\n");
  507: 	    $r->print("</form>\n");
  508: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
  509:   	    $fnum++;
  510: 	}
  511: 
  512: 	if ($indent > 0 and $indent < 11) {
  513: 	    $r->print("<img src=",$iconpath,"whitespace",$indent,".gif border=0>\n");
  514: 	} elsif ($indent >0) {
  515: 	    my $ten = int($indent/10.);
  516: 	    my $rem = $indent%10.0;
  517: 	    my $count = 0;
  518: 	    while ($count < $ten) {
  519: 		$r->print("<img src=",$iconpath,"whitespace10.gif border=0>\n");
  520: 	    $count++;
  521: 	    }
  522: 	    $r->print("<img src=",$iconpath,"whitespace",$rem,".gif border=0>\n") if $rem > 0;
  523: 	}
  524: 
  525: 	$r->print("<img src=$iconpath$curfext.gif border=0>\n");
  526: 	$r->print (" <a href=\"javascript:openWindow('".$filelink."', 'metadatafile', '450', '500', 'no', 'yes')\"; TARGET=_self>$listname</a> ");
  527: 
  528: 	$r->print (" (<a href=\"javascript:openWindow('".$filelink.".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; TARGET=_self>metadata</a>) ") if ($metafile == 1);
  529: 
  530: 	$r->print("</td>\n");
  531: 	$r->print("<td bgcolor=$fileclr align=right valign=bottom> ",$filecom[8]," </td>\n") 
  532: 	    if $hash{'display_attrs_0'} == 1;
  533: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[9]))." </td>\n") 
  534: 	    if $hash{'display_attrs_1'} == 1;
  535: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[10]))." </td>\n") 
  536: 	    if $hash{'display_attrs_2'} == 1;
  537: 
  538: 	if ($hash{'display_attrs_3'} == 1) {
  539: 	    my $author = &Apache::lonnet::metadata($filelink,'author') if ($metafile == 1);
  540: 	    $author = '&nbsp;' if (!$author);
  541: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$author." </td>\n");
  542: 	}
  543: 	if ($hash{'display_attrs_4'} == 1) {
  544: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords') if ($metafile == 1);
  545: 	    $keywords = '&nbsp;' if (!$keywords);
  546: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$keywords." </td>\n");
  547: 	}
  548: 	if ($hash{'display_attrs_5'} == 1) {
  549: 	    my $lang = &Apache::lonnet::metadata($filelink,'language') if ($metafile == 1);
  550: 	    $lang = $language{$lang};
  551: 	    $lang = '&nbsp;' if (!$lang);
  552: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$lang." </td>\n");
  553: 	}
  554: 	$r->print("</tr>\n");
  555:     }
  556: # -- display directory
  557:     if ($fnptr == $dirptr) {
  558: 	my @file_ext = split (/\./,$listname);
  559: 	my $curfext = $file_ext[scalar(@file_ext)-1];
  560: 	my $curdir = $startdir.$filecom[0].'/';
  561: 	my $anchor = $curdir;
  562: 	$anchor =~ s/\///g;
  563: 	$r->print("<tr>$extrafield<td bgcolor=$fileclr valign=bottom>");
  564: 	&begin_form ($r,$curdir);
  565: 	my $indentm1 = $indent-1;
  566: 	if ($indentm1 < 11 and $indentm1 > 0) {
  567: 	    $r->print("<img src=",$iconpath,"whitespace",$indentm1,".gif border=0>\n");
  568: 	} else {
  569: 	    my $ten = int($indentm1/10.);
  570: 	    my $rem = $indentm1%10.0;
  571: 	    my $count = 0;
  572: 	    while ($count < $ten) {
  573: 		$r->print ("<img src=",$iconpath,"whitespace10.gif border=0>\n");
  574: 		$count++;
  575: 	    }
  576: 	    $r->print ("<img src=",$iconpath,"whitespace",$rem,".gif border=0>\n") if $rem > 0;
  577: 	}
  578: 	$r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.'folder_pointer_'.$diropen.'.gif"');
  579: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'."\n");
  580: 	$r->print ('<a href="'.$curdir.'"><img src="'.$iconpath.'folder_'.$diropen.'.gif" border=0></a>'."\n");
  581: 	$r->print ("$listname$tabtag</tr></form>\n");
  582:     }
  583: 
  584: }
  585: 
  586: # ------------------- prints the beginning of a form for directory or file link
  587: sub begin_form {
  588:     my ($r,$uri) = @_;
  589:     my $anchor = $uri;
  590:     $anchor =~ s/\///g;
  591:     $r->print ('<form method="post" name="dirpath" action="'.$uri.'#'.$anchor.
  592: 	       '" enctype="application/x-www-form-urlencoded">'."\n");
  593:     $r->print ($hidden.'<input type=hidden name=openuri value="'.$uri.'">'."\n");
  594:     $r->print ('<input type=hidden name=dirPointer value="on">'."\n");
  595: }
  596: 
  597: 1;
  598: __END__

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