Annotation of loncom/interface/lonindexer.pm, revision 1.4
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.2 harris41 10: #
1.1 www 11: package Apache::lonindexer;
12:
13: use strict;
14: use Apache::lonnet();
15: use Apache::Constants qw(:common);
1.2 harris41 16: use Apache::File;
17: use GDBM_File;
18:
1.4 ! harris41 19: my %hash;
1.2 harris41 20: my %dirs;
21: my %language;
22:
23: sub BEGIN {
24: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/language.tab');
25: map {
26: $_=~/(\w+)\s+([\w\s\-]+)/;
27: $language{$1}=$2;
28: } <$fh>;
29: }
1.1 www 30:
31: sub handler {
32: my $r = shift;
33: $r->content_type('text/html');
34: $r->send_http_header;
35: return OK if $r->header_only;
36:
37: my $iconpath= $r->dir_config('lonIconsURL');
38: my $domain = $r->dir_config('lonDefDomain');
39: my $role = $r->dir_config('lonRole');
40: my $loadlim = $r->dir_config('lonLoadLim');
41: my $servadm = $r->dir_config('lonAdmEMail');
42: my $sysadm = $r->dir_config('lonSysEMail');
43: my $lonhost = $r->dir_config('lonHostID');
44: my $tabdir = $r->dir_config('lonTabDir');
45:
46: # ---------------------------------------------------------------- Print Header
47: $r->print(<<ENDHEADER);
48: <html>
49: <head>
1.2 harris41 50: <title>The LearningOnline Network With CAPA Directory Browser</title>
1.3 harris41 51:
1.2 harris41 52: <SCRIPT language="javascript">
53: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
54: var options = "width=" + w + ",height=" + h + ",";
55: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
56: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
57: var newWin = window.open(url, wdwName, options);
58: newWin.focus();
59: }
60: </SCRIPT>
1.3 harris41 61:
1.1 www 62: </head>
63: <body bgcolor="#FFFFFF">
64: ENDHEADER
65:
66: my $line;
67: my (@attrchk,@openpath);
68: my $uri=$r->uri;
69: my $iconpath="/res/adm/pages/indexericons/";
70:
1.2 harris41 71: $r->print("<h2><font color=\"\#888888\">The LearningOnline With CAPA Network Directory Browser</font></h2>\n");
1.1 www 72:
73: for (my $i=0; $i<=5; $i++) {
74: $attrchk[$i] = "checked" if $ENV{'form.attr'.$i} == 1;
75: }
76: $r->print(<<END);
1.2 harris41 77: <b><font color="#666666">Display file attributes</font></b><br>
1.1 www 78: <form method="post" name="fileattr" action="$uri" enctype="application/x-www-form-urlencoded">
79: <table border=0><tr>
1.2 harris41 80: <td><input type=checkbox name=attr0 value="1" $attrchk[0]> Size</td>
81: <td><input type=checkbox name=attr1 value="1" $attrchk[1]> Last access</td>
82: <td><input type=checkbox name=attr2 value="1" $attrchk[2]> Last modified</td>
1.1 www 83: </tr><tr>
1.2 harris41 84: <td><input type=checkbox name=attr3 value="1" $attrchk[3]> Author</td>
85: <td><input type=checkbox name=attr4 value="1" $attrchk[4]> Keywords</td>
86: <td><input type=checkbox name=attr5 value="1" $attrchk[5]> Language</td>
1.1 www 87: </tr></table>
1.2 harris41 88: <input type="submit" name="dirlistattr" value="Review">
1.1 www 89: <input type="submit" name="dirlistattr" value="Refresh">
90: </form>
91: END
92:
1.4 ! harris41 93: my $diropen = "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_diropen.db";
1.1 www 94:
1.4 ! harris41 95: if (tie(%hash,'GDBM_File',$diropen,&GDBM_WRCREAT,0640)) {
1.2 harris41 96: my $titleclr="#ddffff";
97: $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");
98: $r->print("<table border=0><tr>\n");
99: $r->print("<td bgcolor=$titleclr><b>Name</b></td>\n");
100: $r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) </b></td>\n") if ($ENV{'form.attr0'} == 1);
101: $r->print("<td bgcolor=$titleclr><b>Last accessed</b></td>\n") if ($ENV{'form.attr1'} == 1);
102: $r->print("<td bgcolor=$titleclr><b>Last modified</b></td>\n") if ($ENV{'form.attr2'} == 1);
103: $r->print("<td bgcolor=$titleclr><b>Author(s)</b></td>\n") if ($ENV{'form.attr3'} == 1);
104: $r->print("<td bgcolor=$titleclr><b>Keywords</b></td>\n") if ($ENV{'form.attr4'} == 1);
105: $r->print("<td bgcolor=$titleclr><b>Language</b></td>\n") if ($ENV{'form.attr5'} == 1);
106: $r->print("</tr>");
107:
1.4 ! harris41 108: map {
! 109: if ($_ =~ /^diropen_status_/) {
! 110: my $key = $_;
! 111: $key =~ s/^diropen_status_//;
! 112: $dirs{$key} = $hash{$_};
! 113: }
! 114: } keys %hash;
! 115:
1.2 harris41 116: if ($ENV{'form.openuri'}) { # take care of review and refresh options
117: my $uri=$ENV{'form.openuri'};
1.4 ! harris41 118: if (exists($hash{'diropen_status_'.$uri})) {
! 119: my $cursta = $hash{'diropen_status_'.$uri};
1.2 harris41 120: $dirs{$uri} = 'open';
1.4 ! harris41 121: $hash{'diropen_status_'.$uri} = 'open';
! 122: if ($cursta eq 'open') {
! 123: $dirs{$uri} = 'closed';
! 124: $hash{'diropen_status_'.$uri} = 'closed';
! 125: }
1.2 harris41 126: } else {
1.4 ! harris41 127: $hash{'diropen_status_'.$uri} = 'open';
1.2 harris41 128: $dirs{$uri} = 'open';
129: }
130: }
1.1 www 131:
1.2 harris41 132: my $toplevel = "/res/";
1.4 ! harris41 133: my $indent = 0;
1.2 harris41 134: &scanDir ($r,$toplevel,$indent);
135:
136: $r->print("</table>");
137: $r->print("</td></tr></table>");
138: $r->print("</body></html>\n");
1.4 ! harris41 139: untie(%hash);
1.2 harris41 140: } else {
141: $r->print("Unable to tie hash to db file");
142: }
1.1 www 143: return OK;
144: }
1.2 harris41 145:
146: # --------------------recursive scan of a directory
147: sub scanDir {
148: my ($r,$startdir,$indent)=@_;
1.3 harris41 149: my ($compuri,$curdir);
150: my $dirptr=16384;
1.1 www 151: $indent++;
152:
1.2 harris41 153: my %dupdirs = %dirs;
154: my @list=&get_list($r,$startdir);
155: foreach my $line (@list) {
156: my ($strip,$domusr,$foo,$testdir,$foo)=split(/\&/,$line,5);
1.4 ! harris41 157: next if $strip =~ /.*\.meta$/;
1.2 harris41 158: if ($domusr eq "domain") {
1.3 harris41 159: $compuri = join('',$strip,"/"); # domain list has /res/<domain name>
160: $curdir = $compuri;
1.2 harris41 161: } else {
162: $compuri = join('',$startdir,$strip,"/"); # user, dir & file having name only, i.e., w/o path
1.3 harris41 163: $curdir = $startdir;
1.2 harris41 164: }
165: my $diropen = 0;
1.3 harris41 166: if (($dirptr&$testdir) or ($domusr =~ /^(domain|user)$/)) {
167: while (my ($key,$val)= each %dupdirs) {
168: $diropen = 1 if ($key eq $compuri and $val eq "open");
169: }
1.1 www 170: }
1.4 ! harris41 171: &display_line($r,$diropen,$line,$indent,$curdir,@list);
1.2 harris41 172: &scanDir ($r,$compuri,$indent) if $diropen == 1;
1.1 www 173: }
174: $indent--;
175: }
176:
1.2 harris41 177: # ----------------- get complete matched list based on the uri ------
1.1 www 178: sub get_list {
179: my ($r,$uri)=@_;
180: my @list;
1.2 harris41 181: my $luri = $uri;
182: $luri =~ s/\//_/g;
183:
184: if ($ENV{'form.dirlistattr'} eq "Refresh") {
1.4 ! harris41 185: map {
! 186: delete $hash{$_} if ($_ =~ /^dirlist_files_/);
! 187: } keys %hash;
1.2 harris41 188: }
189:
1.4 ! harris41 190: if ($hash{'dirlist_files'.$luri}) {
! 191: @list = split(/\n/,$hash{'dirlist_files_'.$luri});
1.1 www 192: } else {
1.4 ! harris41 193: @list = &Apache::lonnet::dirlist($uri);
! 194: $hash{'dirlist_files_'.$luri} = join('\n',@list);
1.1 www 195: }
196: return @list=&match_ext($r,@list);
197: }
198:
1.2 harris41 199: #-------------------------- filters out files based on extensions
1.1 www 200: sub match_ext {
201: my ($r,@packlist)=@_;
202: my @trimlist;
203: my $nextline;
204: my @fileext;
205: my $dirptr=16384;
206:
207: my $tabdir = $r->dir_config('lonTabDir');
208: my $fn = $tabdir."/filetypes.tab";
209: if (-e $fn) {
210: my $FH=Apache::File->new($fn);
211: my @content=<$FH>;
1.2 harris41 212: foreach my $line (@content) {
1.1 www 213: (my $ext,my $foo) = split /\s+/,$line;
214: push @fileext,$ext;
215: }
216: }
1.2 harris41 217: foreach my $line (@packlist) {
218: chomp $line;
219: $line =~ s/^\/home\/httpd\/html//;
220: my @unpackline = split (/\&/,$line);
221: next if ($unpackline[0] eq ".");
222: next if ($unpackline[0] eq "..");
223: my @filecom = split (/\./,$unpackline[0]);
224: my $fext = pop(@filecom);
225: my $fnptr = $unpackline[3]&$dirptr;
226: if ($fnptr == 0 and $unpackline[3] ne "") {
227: foreach my $nextline (@fileext) {
228: push @trimlist,$line if $nextline eq $fext;
1.1 www 229: }
230: } else {
1.2 harris41 231: push @trimlist,$line;
1.1 www 232: }
233: }
1.4 ! harris41 234: @trimlist = sort (@trimlist);
1.1 www 235: return @trimlist;
236: }
237:
1.2 harris41 238: #------------------- displays one line in appropriate table format
1.1 www 239: sub display_line{
1.4 ! harris41 240: my ($r,$diropen,$line,$indent,$startdir,@list)=@_;
1.1 www 241: my (@pathfn, $fndir, $fnptr);
242: my $dirptr=16384;
243: my $fileclr="#ffffe6";
244: my $iconpath="/res/adm/pages/indexericons/";
245:
246: my @filecom = split (/\&/,$line);
247: my @pathcom = split (/\//,$filecom[0]);
248: my $listname = $pathcom[scalar(@pathcom)-1];
249: my $fnptr = $filecom[3]&$dirptr;
1.4 ! harris41 250: my $msg = 'View '.$filecom[0].' resources';
! 251: $msg = 'Close '.$filecom[0].' directory' if $diropen == 1;
1.1 www 252:
253: my $tabtag="</td>";
254: my $i=0;
255:
256: while ($i<=5) {
257: my $key="form.attr".$i;
258: $tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,"> </td>") if $ENV{$key} == 1;
259: $i++;
260: }
261: if ($filecom[1] eq "domain") {
262: $r->print("<tr>");
263: $r->print("<td bgcolor=$fileclr valign=bottom>");
1.2 harris41 264: &begin_form ($r,$filecom[0].'/');
1.3 harris41 265: my $anchor = $filecom[0].'/';
266: $anchor =~ s/\///g;
267: $r->print ("<a name=\"".$anchor."\">\n<input src=\"".$iconpath."comp.blue.gif\"");
1.4 ! harris41 268: $r->print (" name=\"$msg\" height=\"22\" type=\"image\" border=\"0\">\n");
1.1 www 269: $r->print("Domain - $listname $tabtag</tr></form>\n");
270: return OK;
271: }
272: if ($filecom[1] eq "user") {
273: $r->print("<tr>");
274: $r->print("<td bgcolor=$fileclr valign=bottom>\n");
1.2 harris41 275: my $curdir = $startdir.$filecom[0].'/';
276: &begin_form ($r,$curdir);
1.3 harris41 277: my $anchor = $curdir;
278: $anchor =~ s/\///g;
1.4 ! harris41 279: # $r->print ("<a name=\"$anchor\">\n<img src=",$iconpath,"white_space_20_22.gif border=0>\n");
! 280: $r->print ("<a name=\"$anchor\">\n<img src=",$iconpath,"whitespace1.gif border=0>\n");
1.1 www 281: $r->print ("<input src=\"$iconpath");
282: $r->print ("folder_pointer_closed.gif\"") if $diropen == 0;
283: $r->print ("folder_pointer_opened.gif\"") if $diropen == 1;
1.4 ! harris41 284: $r->print (" name=\"$msg\" height=\"22\" type=\"image\" border=\"0\">\n");
1.3 harris41 285: $r->print ("<img src=",$iconpath,"quill.gif border=0>\n");
286: $r->print ("$listname $tabtag</tr></form>\n");
1.1 www 287: return OK;
288: }
289: # display file
290: if ($fnptr == 0 and $filecom[3] ne "") {
291: my @file_ext = split (/\./,$listname);
292: my $curfext = $file_ext[scalar(@file_ext)-1];
1.2 harris41 293: my $filelink = $startdir.$filecom[0];
1.1 www 294: $r->print("<tr><td bgcolor=$fileclr>");
1.4 ! harris41 295:
! 296: if ($indent < 11) {
! 297: $r->print("<img src=",$iconpath,"whitespace",$indent,".gif border=0>\n");
! 298: } else {
! 299: my $ten = int($indent/10.);
! 300: my $rem = $indent%10.0;
! 301: my $count = 0;
! 302: while ($count < $ten) {
! 303: $r->print("<img src=",$iconpath,"whitespace10.gif border=0>\n");
1.1 www 304: $count++;
1.4 ! harris41 305: }
! 306: $r->print("<img src=",$iconpath,"whitespace",$rem,".gif border=0>\n") if $rem > 0;
1.1 www 307: }
1.4 ! harris41 308:
1.1 www 309: $r->print("<img src=$iconpath$curfext.gif border=0>\n");
1.4 ! harris41 310: $r->print(" <a href=$filelink>",$listname,"</a>\n");
! 311: my $metafile = grep /^$filecom[0]\.meta\&/, @list;
1.2 harris41 312:
1.4 ! harris41 313: $r->print (" (<a href=\"javascript:openWindow('".$filelink.".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; TARGET=_self>metadata</a>) ") if ($metafile == 1);
1.2 harris41 314:
315: $r=>print("</td>\n");
1.1 www 316: $r->print("<td bgcolor=$fileclr align=right valign=bottom> ",$filecom[8]," </td>\n") if $ENV{'form.attr0'} == 1;
317: $r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[9]))." </td>\n") if $ENV{'form.attr1'} == 1;
318: $r->print("<td bgcolor=$fileclr valign=bottom> ".(localtime($filecom[10]))." </td>\n") if $ENV{'form.attr2'} == 1;
1.2 harris41 319:
320: if ($ENV{'form.attr3'} == 1) {
1.4 ! harris41 321: my $author = &Apache::lonnet::metadata($filelink,'author') if ($metafile == 1);
1.2 harris41 322: $author = ' ' if (!$author);
323: $r->print("<td bgcolor=$fileclr valign=bottom> ".$author." </td>\n");
324: }
325: if ($ENV{'form.attr4'} == 1) {
1.4 ! harris41 326: my $keywords = &Apache::lonnet::metadata($filelink,'keywords') if ($metafile == 1);
1.2 harris41 327: $keywords = ' ' if (!$keywords);
328: $r->print("<td bgcolor=$fileclr valign=bottom> ".$keywords." </td>\n");
329: }
330: if ($ENV{'form.attr5'} == 1) {
1.4 ! harris41 331: my $lang = &Apache::lonnet::metadata($filelink,'language') if ($metafile == 1);
1.2 harris41 332: $lang = $language{$lang};
333: $lang = ' ' if (!$lang);
334: $r->print("<td bgcolor=$fileclr valign=bottom> ".$lang." </td>\n");
335: }
1.1 www 336: $r->print("</tr>\n");
337: }
1.2 harris41 338: # -- display directory
1.1 www 339: if ($fnptr == $dirptr) {
340: my @file_ext = split (/\./,$listname);
341: my $curfext = $file_ext[scalar(@file_ext)-1];
1.2 harris41 342: my $curdir = $startdir.$filecom[0].'/';
1.3 harris41 343: my $anchor = $curdir;
344: $anchor =~ s/\///g;
1.1 www 345: $r->print("<tr><td bgcolor=$fileclr valign=bottom>");
1.2 harris41 346: &begin_form ($r,$curdir);
1.4 ! harris41 347: my $indentm1 = $indent-1;
! 348: if ($indentm1 < 11) {
! 349: $r->print("<img src=",$iconpath,"whitespace",$indentm1,".gif border=0>\n");
! 350: } else {
! 351: my $ten = int($indentm1/10.);
! 352: my $rem = $indentm1%10.0;
! 353: my $count = 0;
! 354: while ($count < $ten) {
! 355: $r->print("<img src=",$iconpath,"whitespace10.gif border=0>\n");
1.1 www 356: $count++;
1.4 ! harris41 357: }
! 358: $r->print("<img src=",$iconpath,"whitespace",$rem,".gif border=0>\n") if $rem > 0;
1.1 www 359: }
1.3 harris41 360: $r->print ("<a name=\"$anchor\">\n<input src=\"$iconpath");
1.1 www 361: $r->print ("folder_pointer_closed.gif\"") if $diropen == 0;
362: $r->print ("folder_pointer_opened.gif\"") if $diropen == 1;
1.4 ! harris41 363: $r->print (" name=\"$msg\" height=\"22\" type=\"image\" border=\"0\">\n");
1.1 www 364: $r->print("<img src=",$iconpath,"folder_closed.gif border=0>\n") if $diropen == 0;
365: $r->print("<img src=",$iconpath,"folder_opened.gif border=0>\n") if $diropen == 1;
366: $r->print("$listname $tabtag</tr></form>\n");
367: }
1.2 harris41 368:
1.1 www 369: }
370:
1.2 harris41 371: #---------------------prints the beginning of a form for directory or file link
1.1 www 372: sub begin_form {
373: my ($r,$uri) = @_;
1.3 harris41 374: my $anchor = $uri;
375: $anchor =~ s/\///g;
376: $r->print ("<form method=\"post\" name=\"dirpath\" action=\"/res/\#$anchor\" enctype=\"application/x-www-form-urlencoded\">\n");
1.2 harris41 377: $r->print ("<input type=hidden name=openuri value=\"$uri\">\n");
1.1 www 378:
379: for (my $i=0; $i<=5; $i++) {
380: $r->print ("<input type=hidden name=attr$i value=\"1\">\n") if $ENV{'form.attr'.$i} == 1;
381: }
382: }
383:
384: 1;
385: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>