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

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.10    ! harris41   53: #    my $iconpath='/res/adm/pages/indexericons/';
1.7       harris41   54:     my $fileclr='#ffffe6';
                     55: # -------------------------------------- see if called from an interactive mode
                     56:     map {
                     57:        my ($name, $value) = split(/=/,$_);
                     58:        $value =~ tr/+/ /;
                     59:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                     60:        if ($name eq 'catalogmode') {
                     61:            $ENV{'form.'.$name}=$value;
                     62: 	   }
                     63:     } (split(/&/,$ENV{'QUERY_STRING'}));
                     64: 
                     65:     $hidden=''; my $closebutton='';
                     66:     my $groupimportbutton='';
                     67:     my $colspan=''; 
                     68:     if ($ENV{'form.catalogmode'} eq 'interactive') {
                     69: 	$extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
                     70: 	    '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
                     71: 	    ' border="0"></td>';
                     72: 	$colspan=" colspan='2' ";
                     73: 	$hidden=<<END;
                     74: <input type='hidden' name='catalogmode' value='interactive'>
                     75: END
                     76:         $closebutton=<<END;
                     77: <input type="button" name="close" value='CLOSE' onClick="self.close()">
                     78: END
                     79:     }
                     80:     elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
1.8       harris41   81: 	$extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
                     82: 	    '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
                     83: 	    ' border="0"></td>';
1.7       harris41   84: 	$colspan=" colspan='2' ";
                     85: 	$hidden=<<END;
                     86: <input type='hidden' name='catalogmode' value='groupimport'>
                     87: END
                     88:         $closebutton=<<END;
                     89: <input type="button" name="close" value='CLOSE' onClick="self.close()">
                     90: END
                     91:         $groupimportbutton=<<END;
1.8       harris41   92: <input type="button" name="groupimport" value='GROUP IMPORT' onClick="javascript:select_group()">
1.7       harris41   93: END
                     94:     }
                     95: 
                     96:     my $catalogmodefunctions='';
                     97:     if ($ENV{'form.catalogmode'} eq 'interactive' or
                     98: 	$ENV{'form.catalogmode'} eq 'groupimport') {
                     99: 	$catalogmodefunctions=<<END;
                    100: function select_data(title,url) {
                    101:     changeTitle(title);
                    102:     changeURL(url);
1.8       harris41  103:     self.close();
                    104: }
                    105: function save_group() {
                    106:     for (var num=0; num<document.forms.fnum.fnum.value; num++) {
                    107: 	if (eval("document.forms.form"+num+".filelink.checked")) {
                    108: 	    alert(eval("document.forms.form"+num+".title.value")+
                    109: 		       eval("document.forms.form"+num+".filelink.value"));
                    110: 	}
                    111:     }
                    112: }
                    113: function select_group() {
1.9       harris41  114:     var linkflag=false;
1.8       harris41  115:     for (var num=0; num<document.forms.fnum.fnum.value; num++) {
                    116: 	if (eval("document.forms.form"+num+".filelink.checked")) {
1.9       harris41  117: //	    alert(eval("document.forms.form"+num+".title.value")+
                    118: //		       eval("document.forms.form"+num+".filelink.value"));
                    119: 	    insertRowInLastRow();
                    120: 	    placeResourceInLastRow(
                    121: 		   eval("document.forms.form"+num+".title.value"),
                    122: 		   eval("document.forms.form"+num+".filelink.value"),
                    123: 		   linkflag
                    124: 				   );
                    125: 	    linkflag=true;
1.8       harris41  126: 	}
                    127:     }
1.9       harris41  128:     opener.editmode=0;
                    129:     opener.notclear=0;
                    130:     opener.linkmode=0;
                    131:     opener.infoclear();
                    132:     opener.draw();
                    133: }
                    134: function insertRowInLastRow() {
                    135:     opener.insertrow(opener.maxrow);
                    136:     opener.addobj(opener.maxrow,'e&2');
                    137: }
                    138: function placeResourceInLastRow (title,url,linkflag) {
                    139:     opener.newresource(opener.maxrow,2,opener.escape(title),opener.escape(url),'false','normal');
                    140:     opener.save();
                    141:     opener.mostrecent=opener.obj.length-1;
                    142:     if (linkflag) {
                    143: 	opener.joinres(opener.linkmode,opener.mostrecent,0);
                    144:     }
                    145:     opener.linkmode=opener.mostrecent;
1.7       harris41  146: }
                    147: function changeTitle(val) {
                    148:     if (opener.inf.document.forms.resinfo.elements.t) {
                    149:         opener.inf.document.forms.resinfo.elements.t.value=val;
                    150:     }
                    151: }
                    152: function changeURL(val) {
                    153:     if (opener.inf.document.forms.resinfo.elements.u) {
                    154: 	opener.inf.document.forms.resinfo.elements.u.value=val;
                    155:     }
                    156: }
                    157: END
                    158:     }
                    159: 
1.1       www       160: # ---------------------------------------------------------------- Print Header
                    161:     $r->print(<<ENDHEADER);
                    162: <html>
                    163: <head>
1.2       harris41  164: <title>The LearningOnline Network With CAPA Directory Browser</title>
1.3       harris41  165: 
1.2       harris41  166: <SCRIPT language="javascript">
1.7       harris41  167: $catalogmodefunctions
1.2       harris41  168: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                    169:     var options = "width=" + w + ",height=" + h + ",";
                    170:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                    171:     options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                    172:     var newWin = window.open(url, wdwName, options);
                    173:     newWin.focus();
                    174: }
                    175: </SCRIPT>
1.3       harris41  176: 
1.1       www       177: </head>
                    178: <body bgcolor="#FFFFFF">
                    179: ENDHEADER
                    180: 
                    181:     my $line;
                    182:     my (@attrchk,@openpath);
                    183:     my $uri=$r->uri;
                    184: 
1.2       harris41  185:     $r->print("<h2><font color=\"\#888888\">The LearningOnline With CAPA Network Directory Browser</font></h2>\n");
1.1       www       186: 
1.6       harris41  187:     my $diropen = "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
                    188: 
                    189:     if (tie(%hash,'GDBM_File',$diropen,&GDBM_WRCREAT,0640)) {
                    190: 
                    191: 	if ($ENV{'form.attrs'} ne "") {
                    192: 	    for (my $i=0; $i<=5; $i++) {
                    193: 		delete $hash{'display_attrs_'.$i};
                    194: 		if ($ENV{'form.attr'.$i} == 1) {
                    195: 		    $attrchk[$i] = "checked";
                    196: 		    $hash{'display_attrs_'.$i} = 1;
                    197: 		}
                    198: 	    }
                    199: 	} else {
                    200: 	    for (my $i=0; $i<=5; $i++) {
                    201: 		$attrchk[$i] = "checked" if $hash{'display_attrs_'.$i} == 1;
                    202: 	    }
                    203: 	}
1.1       www       204:     $r->print(<<END);
1.2       harris41  205: <b><font color="#666666">Display file attributes</font></b><br>
1.1       www       206: <form method="post" name="fileattr" action="$uri" enctype="application/x-www-form-urlencoded">
                    207: <table border=0><tr>
1.2       harris41  208: <td><input type=checkbox name=attr0 value="1" $attrchk[0]> Size</td>
                    209: <td><input type=checkbox name=attr1 value="1" $attrchk[1]> Last access</td>
                    210: <td><input type=checkbox name=attr2 value="1" $attrchk[2]> Last modified</td>
1.1       www       211: </tr><tr>
1.2       harris41  212: <td><input type=checkbox name=attr3 value="1" $attrchk[3]> Author</td>
                    213: <td><input type=checkbox name=attr4 value="1" $attrchk[4]> Keywords</td>
                    214: <td><input type=checkbox name=attr5 value="1" $attrchk[5]> Language</td>
1.1       www       215: </tr></table>
1.6       harris41  216: <input type="submit" name="attrs" value="Review">&nbsp;
                    217: <input type="submit" name="attrs" value="Refresh">
1.7       harris41  218: $hidden
                    219: $closebutton
                    220: $groupimportbutton
1.1       www       221: </form>
                    222: END
                    223: 
1.5       harris41  224:     my $titleclr="#ddffff";
                    225:     $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");
                    226:     $r->print("<table border=0><tr>\n");
1.7       harris41  227:     $r->print("<td $colspan bgcolor=$titleclr><b>Name</b></td>\n");
1.6       harris41  228:     $r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) </b></td>\n") if ($hash{'display_attrs_0'} == 1);
                    229:     $r->print("<td bgcolor=$titleclr><b>Last accessed</b></td>\n") if ($hash{'display_attrs_1'} == 1);
                    230:     $r->print("<td bgcolor=$titleclr><b>Last modified</b></td>\n") if ($hash{'display_attrs_2'} == 1);
                    231:     $r->print("<td bgcolor=$titleclr><b>Author(s)</b></td>\n") if ($hash{'display_attrs_3'} == 1);
                    232:     $r->print("<td bgcolor=$titleclr><b>Keywords</b></td>\n") if ($hash{'display_attrs_4'} == 1);
                    233:     $r->print("<td bgcolor=$titleclr><b>Language</b></td>\n") if ($hash{'display_attrs_5'} == 1);
1.5       harris41  234:     $r->print("</tr>");
                    235: 
1.4       harris41  236: 	map {
                    237: 	    if ($_ =~ /^diropen_status_/) {
                    238: 		my $key = $_;
                    239: 		$key =~ s/^diropen_status_//;
                    240: 		$dirs{$key} = $hash{$_};
                    241: 	    }
                    242: 	} keys %hash;
                    243: 
1.2       harris41  244: 	if ($ENV{'form.openuri'}) {  # take care of review and refresh options
                    245: 	    my $uri=$ENV{'form.openuri'};
1.4       harris41  246: 	    if (exists($hash{'diropen_status_'.$uri})) {
                    247: 		my $cursta = $hash{'diropen_status_'.$uri};
1.2       harris41  248: 		$dirs{$uri} = 'open';
1.4       harris41  249: 		$hash{'diropen_status_'.$uri} = 'open';
                    250: 		if ($cursta eq 'open') {
                    251: 		    $dirs{$uri} = 'closed';
                    252: 		    $hash{'diropen_status_'.$uri} = 'closed';
                    253: 		}
1.2       harris41  254: 	    } else {
1.4       harris41  255: 		$hash{'diropen_status_'.$uri} = 'open';
1.2       harris41  256: 		$dirs{$uri} = 'open';
                    257: 	    }
                    258: 	}
1.1       www       259: 
1.2       harris41  260: 	my $toplevel = "/res/";
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: 	}
                    296: 	my $diropen = 0;
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") {
                    300: 		    $diropen = 1;
                    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.2       harris41  306: 	&scanDir ($r,$compuri,$indent) if $diropen == 1;
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') . "/";
        !           379: #    my $iconpath="/res/adm/pages/indexericons/";
1.1       www       380: 
                    381:     my @filecom = split (/\&/,$line);
                    382:     my @pathcom = split (/\//,$filecom[0]);
                    383:     my $listname = $pathcom[scalar(@pathcom)-1];
                    384:     my $fnptr = $filecom[3]&$dirptr;
1.4       harris41  385:     my $msg = 'View '.$filecom[0].' resources';
                    386:     $msg = 'Close '.$filecom[0].' directory' if $diropen == 1;
1.1       www       387: 
                    388:     my $tabtag="</td>";
                    389:     my $i=0;
                    390: 
                    391:     while ($i<=5) {
1.6       harris41  392: #	my $key="form.attr".$i;
                    393: #	$tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,">&nbsp;</td>") if $ENV{$key} == 1;
                    394: 	$tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,">&nbsp;</td>") if $hash{'display_attrs_'.$i} == 1;
1.1       www       395: 	$i++;
                    396:     }
                    397:     if ($filecom[1] eq "domain") {
1.7       harris41  398: 	$r->print("<tr>$extrafield");
1.1       www       399: 	$r->print("<td bgcolor=$fileclr valign=bottom>");
1.2       harris41  400: 	&begin_form ($r,$filecom[0].'/');
1.3       harris41  401: 	my $anchor = $filecom[0].'/';
                    402: 	$anchor =~ s/\///g;
1.10    ! harris41  403: 	$r->print ("<a name=\"".$anchor."\">\n<input src=\"".$iconpath."server.gif\"");
1.4       harris41  404: 	$r->print (" name=\"$msg\" height=\"22\" type=\"image\" border=\"0\">\n");
1.1       www       405: 	$r->print("Domain - $listname $tabtag</tr></form>\n");
                    406: 	return OK;
                    407:     }
                    408:     if ($filecom[1] eq "user") {
1.7       harris41  409: 	$r->print("<tr>$extrafield");
1.1       www       410: 	$r->print("<td bgcolor=$fileclr valign=bottom>\n");
1.2       harris41  411: 	my $curdir = $startdir.$filecom[0].'/';
                    412: 	&begin_form ($r,$curdir);
1.3       harris41  413: 	my $anchor = $curdir;
                    414: 	$anchor =~ s/\///g;
1.4       harris41  415: #	$r->print ("<a name=\"$anchor\">\n<img src=",$iconpath,"white_space_20_22.gif border=0>\n");
                    416: 	$r->print ("<a name=\"$anchor\">\n<img src=",$iconpath,"whitespace1.gif border=0>\n");
1.1       www       417: 	$r->print ("<input src=\"$iconpath");
                    418: 	$r->print ("folder_pointer_closed.gif\"") if $diropen == 0;
                    419: 	$r->print ("folder_pointer_opened.gif\"") if $diropen == 1;
1.4       harris41  420: 	$r->print (" name=\"$msg\" height=\"22\" type=\"image\" border=\"0\">\n");
1.3       harris41  421: 	$r->print ("<img src=",$iconpath,"quill.gif border=0>\n");
                    422: 	$r->print ("$listname $tabtag</tr></form>\n");
1.1       www       423: 	return OK;
                    424:     }
                    425: # display file
                    426:     if ($fnptr == 0 and $filecom[3] ne "") {
                    427: 	my @file_ext = split (/\./,$listname);
                    428: 	my $curfext = $file_ext[scalar(@file_ext)-1];
1.2       harris41  429: 	my $filelink = $startdir.$filecom[0];
1.8       harris41  430: 	$r->print("<tr><td nowrap valign='bottom' bgcolor=$fileclr>");
1.7       harris41  431: 	my $metafile = grep /^$filecom[0]\.meta\&/, @list;
                    432: 	my $title;
                    433:         if ($ENV{'form.catalogmode'} eq 'interactive') {
                    434: 	    $title=$listname;
1.8       harris41  435: 	    $title = &Apache::lonnet::metadata($filelink,'title')
                    436: 		if ($metafile == 1);
1.7       harris41  437: 	    $title=$listname unless $title;
                    438: 	    $r->print("<a href='javascript:select_data(\"",
                    439: 	              $title,'","',$filelink,"\")'>");
                    440: 	    $r->print("<img src='",$iconpath,"select.gif' border=0></a>\n");
1.8       harris41  441: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
                    442: 	}
                    443:         elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
                    444: 	    $title=$listname;
                    445: 	    $title = &Apache::lonnet::metadata($filelink,'title')
                    446: 		if ($metafile == 1);
                    447: 	    $title=$listname unless $title;
                    448: 	    $r->print("<form name='form$fnum'>\n");
                    449: 	    $r->print("<input type='checkbox' name='filelink"."' ".
                    450: 		      "value='$filelink'>\n");
                    451: 	    $r->print("<input type='hidden' name='title"."' ".
                    452: 		      "value='$title'>\n");
                    453: 	    $r->print("</form>\n");
                    454: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
                    455:   	    $fnum++;
1.7       harris41  456: 	}
1.4       harris41  457: 
                    458: 	if ($indent < 11) {
                    459: 	    $r->print("<img src=",$iconpath,"whitespace",$indent,".gif border=0>\n");
                    460: 	} else {
                    461: 	    my $ten = int($indent/10.);
                    462: 	    my $rem = $indent%10.0;
                    463: 	    my $count = 0;
                    464: 	    while ($count < $ten) {
                    465: 		$r->print("<img src=",$iconpath,"whitespace10.gif border=0>\n");
1.1       www       466: 	    $count++;
1.4       harris41  467: 	    }
                    468: 	    $r->print("<img src=",$iconpath,"whitespace",$rem,".gif border=0>\n") if $rem > 0;
1.1       www       469: 	}
1.4       harris41  470: 
1.1       www       471: 	$r->print("<img src=$iconpath$curfext.gif border=0>\n");
1.7       harris41  472: 	$r->print(" <a href=$filelink target='_blank'>",$listname,"</a>\n");
1.2       harris41  473: 
1.4       harris41  474: 	$r->print (" (<a href=\"javascript:openWindow('".$filelink.".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; TARGET=_self>metadata</a>) ") if ($metafile == 1);
1.2       harris41  475: 
1.7       harris41  476: 	$r->print("</td>\n");
1.6       harris41  477: #	$r->print("<td bgcolor=$fileclr align=right valign=bottom> ",$filecom[8]," </td>\n") if $ENV{'form.attr0'} == 1;
                    478: 	$r->print("<td bgcolor=$fileclr align=right valign=bottom> ",$filecom[8]," </td>\n") if $hash{'display_attrs_0'} == 1;
                    479: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[9]))." </td>\n") if $hash{'display_attrs_1'} == 1;
                    480: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[10]))." </td>\n") if $hash{'display_attrs_2'} == 1;
1.2       harris41  481: 
1.6       harris41  482: 	if ($hash{'display_attrs_3'} == 1) {
1.4       harris41  483: 	    my $author = &Apache::lonnet::metadata($filelink,'author') if ($metafile == 1);
1.2       harris41  484: 	    $author = '&nbsp;' if (!$author);
                    485: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$author." </td>\n");
                    486: 	}
1.6       harris41  487: 	if ($hash{'display_attrs_4'} == 1) {
1.4       harris41  488: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords') if ($metafile == 1);
1.2       harris41  489: 	    $keywords = '&nbsp;' if (!$keywords);
                    490: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$keywords." </td>\n");
                    491: 	}
1.6       harris41  492: 	if ($hash{'display_attrs_5'} == 1) {
1.4       harris41  493: 	    my $lang = &Apache::lonnet::metadata($filelink,'language') if ($metafile == 1);
1.2       harris41  494: 	    $lang = $language{$lang};
                    495: 	    $lang = '&nbsp;' if (!$lang);
                    496: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$lang." </td>\n");
                    497: 	}
1.1       www       498: 	$r->print("</tr>\n");
                    499:     }
1.2       harris41  500: # -- display directory
1.1       www       501:     if ($fnptr == $dirptr) {
                    502: 	my @file_ext = split (/\./,$listname);
                    503: 	my $curfext = $file_ext[scalar(@file_ext)-1];
1.2       harris41  504: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41  505: 	my $anchor = $curdir;
                    506: 	$anchor =~ s/\///g;
1.7       harris41  507: 	$r->print("<tr>$extrafield<td bgcolor=$fileclr valign=bottom>");
1.2       harris41  508: 	&begin_form ($r,$curdir);
1.4       harris41  509: 	my $indentm1 = $indent-1;
                    510: 	if ($indentm1 < 11) {
                    511: 	    $r->print("<img src=",$iconpath,"whitespace",$indentm1,".gif border=0>\n");
                    512: 	} else {
                    513: 	    my $ten = int($indentm1/10.);
                    514: 	    my $rem = $indentm1%10.0;
                    515: 	    my $count = 0;
                    516: 	    while ($count < $ten) {
                    517: 		$r->print("<img src=",$iconpath,"whitespace10.gif border=0>\n");
1.1       www       518: 	    $count++;
1.4       harris41  519: 	    }
                    520: 	    $r->print("<img src=",$iconpath,"whitespace",$rem,".gif border=0>\n") if $rem > 0;
1.1       www       521: 	}
1.3       harris41  522: 	$r->print ("<a name=\"$anchor\">\n<input src=\"$iconpath");
1.1       www       523: 	$r->print ("folder_pointer_closed.gif\"") if $diropen == 0;
                    524: 	$r->print ("folder_pointer_opened.gif\"") if $diropen == 1;
1.4       harris41  525: 	$r->print (" name=\"$msg\" height=\"22\" type=\"image\" border=\"0\">\n");
1.1       www       526: 	$r->print("<img src=",$iconpath,"folder_closed.gif border=0>\n") if $diropen == 0;
                    527: 	$r->print("<img src=",$iconpath,"folder_opened.gif border=0>\n") if $diropen == 1;
                    528: 	$r->print("$listname $tabtag</tr></form>\n");
                    529:     }
1.2       harris41  530: 
1.1       www       531: }
                    532: 
1.2       harris41  533: #---------------------prints the beginning of a form for directory or file link
1.1       www       534: sub begin_form {
                    535:     my ($r,$uri) = @_;
1.3       harris41  536:     my $anchor = $uri;
                    537:     $anchor =~ s/\///g;
                    538:     $r->print ("<form method=\"post\" name=\"dirpath\" action=\"/res/\#$anchor\" enctype=\"application/x-www-form-urlencoded\">\n");
1.7       harris41  539:     $r->print ("$hidden<input type=hidden name=openuri value=\"$uri\">\n");
1.1       www       540: 
1.6       harris41  541: #    for (my $i=0; $i<=5; $i++) {
                    542: #	$r->print ("<input type=hidden name=attr$i value=\"1\">\n") if $ENV{'form.attr'.$i} == 1;
                    543: #    }
1.1       www       544: }
                    545: 
                    546: 1;
                    547: __END__

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