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

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

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