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