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

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

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