1: # The LearningOnline Network with CAPA
2: #
3: # Directory Indexer
4: #
5: # YEAR=1999
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: # YEAR=2000
9: # 07/20-08/04 H.K. Ng
10: # YEAR=2001
11: # 05/9-05/19/2001 H. K. Ng
12: # 05/21/2001 H. K. Ng
13: # 05/23/2001 H. K. Ng
14: # 5/31,6/1,6/2,6/15 Scott Harrison
15: # 6/26,7/8 H. K. Ng
16: # 8/6,8/7,8/10 Scott Harrison
17: # 8/14 H. K. Ng
18: # 8/28,10/15 Scott Harrison
19:
20: package Apache::lonindexer;
21:
22: use strict;
23: use Apache::lonnet();
24: use Apache::Constants qw(:common);
25: use Apache::File;
26: use GDBM_File;
27:
28: my %hash; # tied to a user-specific gdbm file
29: my %dirs; # keys are directories, values are the open/close status
30: my %language; # has the reference information present in language.tab
31:
32: # ----- Values which are set by the handler subroutine and are accessible to
33: # ----- other methods.
34: my $extrafield; # default extra table cell
35: my $fnum; # file counter
36: my $dnum; # directory counter
37:
38: # ---------------------------------------------------------------------- BEGIN
39: sub BEGIN {
40: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
41: '/language.tab');
42: map {
43: $_=~/(\w+)\s+([\w\s\-]+)/;
44: $language{$1}=$2;
45: } <$fh>;
46: }
47:
48: # ---------------------------------------------------------------- Main Handler
49: sub handler {
50: my $r = shift;
51: $r->content_type('text/html');
52: $r->send_http_header;
53: return OK if $r->header_only;
54: $fnum=0;
55: $dnum=0;
56: untie %hash;
57:
58: # --------------------------------------------- machine configuration variables
59: my $iconpath= $r->dir_config('lonIconsURL') . "/";
60: my $domain = $r->dir_config('lonDefDomain');
61: my $role = $r->dir_config('lonRole');
62: my $loadlim = $r->dir_config('lonLoadLim');
63: my $servadm = $r->dir_config('lonAdmEMail');
64: my $sysadm = $r->dir_config('lonSysEMail');
65: my $lonhost = $r->dir_config('lonHostID');
66: my $tabdir = $r->dir_config('lonTabDir');
67:
68: my $fileclr='#ffffe6';
69: my $line;
70: my (@attrchk,@openpath);
71: my $uri=$r->uri;
72:
73: # -------------------------------------- see if called from an interactive mode
74: &get_unprocessed_cgi();
75:
76: my $closebutton='';
77: my $groupimportbutton='';
78: my $colspan='';
79:
80: $extrafield='';
81: my $diropendb =
82: "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
83:
84: if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
85: if ($ENV{'form.launch'} eq '1') {
86: &start_fresh_session();
87: }
88:
89: # -------------------- refresh environment with user database values (in %hash)
90: if ($hash{'mode_catalog'} eq 'interactive') {
91: $ENV{'form.catalogmode'}='interactive';
92: }
93: if ($hash{'mode_catalog'} eq 'groupimport') {
94: $ENV{'form.catalogmode'}='groupimport';
95: }
96:
97: # --------------------- define extra fields and buttons in case of special mode
98: if ($ENV{'form.catalogmode'} eq 'interactive') {
99: $hash{'mode_catalog'}='interactive';
100: $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
101: '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
102: ' border="0" /></td>';
103: $colspan=" colspan='2' ";
104: $closebutton=<<END;
105: <input type="button" name="close" value='CLOSE' onClick="self.close()">
106: END
107: }
108: elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
109: $hash{'mode_catalog'}='groupimport';
110: $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
111: '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
112: ' border="0" /></td>';
113: $colspan=" colspan='2' ";
114: $closebutton=<<END;
115: <input type="button" name="close" value='CLOSE' onClick="self.close()">
116: END
117: $groupimportbutton=<<END;
118: <input type="button" name="groupimport" value='GROUP IMPORT'
119: onClick="javascript:select_group()">
120: END
121: }
122:
123: # ------ set catalogmodefunctions to have extra needed javascript functionality
124: my $catalogmodefunctions='';
125: if ($ENV{'form.catalogmode'} eq 'interactive' or
126: $ENV{'form.catalogmode'} eq 'groupimport') {
127: $catalogmodefunctions=<<END;
128: function select_data(title,url) {
129: changeTitle(title);
130: changeURL(url);
131: self.close();
132: }
133: function select_group() {
134: window.location="/adm/groupsort?catalogmode=groupimport&acts="+document.forms.fileattr.acts.value;
135: }
136: function changeTitle(val) {
137: if (opener.inf.document.forms.resinfo.elements.t) {
138: opener.inf.document.forms.resinfo.elements.t.value=val;
139: }
140: }
141: function changeURL(val) {
142: if (opener.inf.document.forms.resinfo.elements.u) {
143: opener.inf.document.forms.resinfo.elements.u.value=val;
144: }
145: }
146: END
147: }
148: if ($ENV{'form.catalogmode'} eq 'groupimport') {
149: $catalogmodefunctions.=<<END;
150: var acts='';
151: function queue(val) {
152: if (eval("document.forms."+val+".filelink.checked")) {
153: var l=val.length;
154: var v=val.substring(4,l);
155: document.forms.fileattr.acts.value+='1a'+v+'b';
156: }
157: else {
158: var l=val.length;
159: var v=val.substring(4,l);
160: document.forms.fileattr.acts.value+='0a'+v+'b';
161: }
162: }
163: function rep_dirpath(suffix,val) {
164: eval("document.forms.dirpath"+suffix+".acts.value=val");
165: }
166: END
167: }
168:
169: # ---------------------------------------------------------------- Print Header
170: $r->print(<<ENDHEADER);
171: <html>
172: <head>
173: <title>The LearningOnline Network With CAPA Directory Browser</title>
174:
175: <script type="text/javascript">
176: $catalogmodefunctions
177: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
178: var options = "width=" + w + ",height=" + h + ",";
179: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
180: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
181: var newWin = window.open(url, wdwName, options);
182: newWin.focus();
183: }
184: function gothere(val) {
185: window.location=val+'?acts='+document.forms.fileattr.acts.value;
186: }
187: </script>
188:
189: </head>
190: <body bgcolor="#FFFFFF">
191: ENDHEADER
192:
193: # - Evaluate actions from previous page (both cumulatively and chronologically)
194: if ($ENV{'form.catalogmode'} eq 'groupimport') {
195: my $acts=$ENV{'form.acts'};
196: my @Acts=split(/b/,$acts);
197: my %ahash;
198: my %achash;
199: my $ac=0;
200: # some initial hashes for working with data
201: map {
202: my ($state,$ref)=split(/a/);
203: $ahash{$ref}=$state;
204: $achash{$ref}=$ac;
205: $ac++;
206: } (@Acts);
207: # sorting through the actions and changing the tied database hash
208: map {
209: my $key=$_;
210: if ($ahash{$key} eq '1') {
211: $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
212: $hash{'pre_'.$key.'_title'};
213: $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
214: $hash{'storectr'}+0;
215: $hash{'storectr'}++;
216: }
217: if ($ahash{$key} eq '0') {
218: if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
219: delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
220: }
221: }
222: } sort {$achash{$a}<=>$achash{$b}} (keys %ahash);
223: # deleting the previously cached listing
224: map {
225: if ($_ =~ /^pre_/ && $_ =~/link$/) {
226: my $key = $_;
227: $key =~ s/^pre_//;
228: $key =~ s/_[^_]*$//;
229: delete $hash{'pre_'.$key.'_title'};
230: delete $hash{'pre_'.$key.'_link'};
231: }
232: } keys %hash;
233: }
234:
235: # output title
236: $r->print('<h2><font color="#888888">The LearningOnline With CAPA '.
237: 'Network Directory Browser</font></h2>'."\n");
238: # get state of file attributes to be showing
239: if ($ENV{'form.attrs'} ne "") {
240: for (my $i=0; $i<=6; $i++) {
241: delete $hash{'display_attrs_'.$i};
242: if ($ENV{'form.attr'.$i} == 1) {
243: $attrchk[$i] = "checked";
244: $hash{'display_attrs_'.$i} = 1;
245: }
246: }
247: } else {
248: for (my $i=0; $i<=6; $i++) {
249: $attrchk[$i] = "checked" if $hash{'display_attrs_'.$i} == 1;
250: }
251: }
252: # output state of file attributes to be showing
253: $r->print(<<END);
254: <b><font color="#666666">Display file attributes</font></b><br />
255: <form method="post" name="fileattr" action="$uri"
256: enctype="application/x-www-form-urlencoded">
257: <table border=0><tr>
258: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] /> Size</td>
259: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> Last access</td>
260: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> Last modified</td>
261: <td><input type="checkbox" name="attr6" value="1" $attrchk[6] /> All versions</td>
262: </tr><tr>
263: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> Author</td>
264: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> Keywords</td>
265: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> Language</td>
266: <td> </td>
267: </tr></table>
268: <input type="hidden" name="dirPointer" value="on" />
269: <input type="hidden" name="acts" value="" />
270: <input type="submit" name="attrs" value="Review" />
271: <input type="submit" name="attrs" value="Refresh" />
272: $closebutton
273: $groupimportbutton
274: </form>
275: END
276:
277: # output starting row to the indexed file/directory hierarchy
278: my $titleclr="#ddffff";
279: $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");
280: $r->print("<table border=0><tr>\n");
281: $r->print("<td $colspan bgcolor=$titleclr><b>Name</b></td>\n");
282: $r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) ".
283: "</b></td>\n") if ($hash{'display_attrs_0'} == 1);
284: $r->print("<td bgcolor=$titleclr><b>Last accessed</b></td>\n")
285: if ($hash{'display_attrs_1'} == 1);
286: $r->print("<td bgcolor=$titleclr><b>Last modified</b></td>\n")
287: if ($hash{'display_attrs_2'} == 1);
288: $r->print("<td bgcolor=$titleclr><b>Author(s)</b></td>\n")
289: if ($hash{'display_attrs_3'} == 1);
290: $r->print("<td bgcolor=$titleclr><b>Keywords</b></td>\n")
291: if ($hash{'display_attrs_4'} == 1);
292: $r->print("<td bgcolor=$titleclr><b>Language</b></td>\n")
293: if ($hash{'display_attrs_5'} == 1);
294: $r->print("</tr>");
295:
296: # read in what directories have previously been set to "open"
297: map {
298: if ($_ =~ /^diropen_status_/) {
299: my $key = $_;
300: $key =~ s/^diropen_status_//;
301: $dirs{$key} = $hash{$_};
302: }
303: } keys %hash;
304:
305: if ($ENV{'form.openuri'}) { # take care of review and refresh options
306: my $uri=$ENV{'form.openuri'};
307: if (exists($hash{'diropen_status_'.$uri})) {
308: my $cursta = $hash{'diropen_status_'.$uri};
309: $dirs{$uri} = 'open';
310: $hash{'diropen_status_'.$uri} = 'open';
311: if ($cursta eq 'open') {
312: $dirs{$uri} = 'closed';
313: $hash{'diropen_status_'.$uri} = 'closed';
314: }
315: } else {
316: $hash{'diropen_status_'.$uri} = 'open';
317: $dirs{$uri} = 'open';
318: }
319: }
320:
321: my $bredir = $ENV{'form.dirPointer'};
322: my $toplevel;
323: my $indent = 0;
324: $uri = $uri.'/' if $uri !~ /.*\/$/;
325:
326: if ($bredir ne "on") {
327: $hash{'top.level'} = $uri;
328: $toplevel = $uri;
329:
330: } else {
331: $toplevel = $hash{'top.level'};
332: }
333:
334: # if not at top level, provide an uplink arrow
335: if ($toplevel ne "/res/"){
336: my (@uri_com) = split(/\//,$uri);
337: pop @uri_com;
338: my $upone = join('/',@uri_com);
339: my @list = qw (0);
340: &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
341: $indent = 1;
342: }
343:
344: # recursively go through all the directories and output as appropriate
345: &scanDir ($r,$toplevel,$indent,\%hash);
346:
347: # information useful for group import
348: $r->print("<form name='fnum'>");
349: $r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
350:
351: # end the tables
352: $r->print("</table>");
353: $r->print("</td></tr></table>");
354:
355: # end the output and return
356: $r->print("</body></html>\n");
357: untie(%hash);
358: } else {
359: $r->print('<html><head></head><body>Unable to tie hash to db '.
360: 'file</body></html>');
361: return OK;
362: }
363: return OK;
364: }
365:
366:
367: # ----------------------------------------------- recursive scan of a directory
368: sub scanDir {
369: my ($r,$startdir,$indent,$hashref)=@_;
370: my ($compuri,$curdir);
371: my $dirptr=16384;
372: $indent++;
373:
374: my %dupdirs = %dirs;
375: my @list=&get_list($r,$startdir);
376: foreach my $line (@list) {
377: my ($strip,$dom,$foo,$testdir,$foo)=split(/\&/,$line,5);
378: next if $strip =~ /.*\.meta$/;
379: my (@fileparts) = split(/\./,$strip);
380: if ($hash{'display_attrs_6'} != 1) {
381: if (scalar(@fileparts) >= 3) {
382: my $fext = pop @fileparts;
383: my $ov = pop @fileparts;
384: my $fname = join ('.',@fileparts,$fext);
385: next if (grep /$fname/,@list and $ov =~ /\d+/);
386: }
387: }
388:
389: if ($dom eq "domain") {
390: $compuri = join('',$strip,"/"); # dom list has /res/<domain name>
391: $curdir = $compuri;
392: } else {
393: # user, dir & file have name only, i.e., w/o path
394: $compuri = join('',$startdir,$strip,"/");
395: $curdir = $startdir;
396: }
397: my $diropen = "closed";
398: if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/)) {
399: while (my ($key,$val)= each %dupdirs) {
400: if ($key eq $compuri and $val eq "open") {
401: $diropen = "opened";
402: delete $dupdirs{key},$dirs{$key};
403: }
404: }
405: }
406: &display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
407: &scanDir ($r,$compuri,$indent) if $diropen eq "opened";
408: }
409: $indent--;
410: }
411:
412: # --------------- get complete matched list based on the uri (returns an array)
413: sub get_list {
414: my ($r,$uri)=@_;
415: my @list;
416: my $luri = $uri;
417: $luri =~ s/\//_/g;
418:
419: if ($ENV{'form.attrs'} eq "Refresh") {
420: map {
421: delete $hash{$_} if ($_ =~ /^dirlist_files_/);
422: } keys %hash;
423: }
424:
425: if ($hash{'dirlist_files'.$luri}) {
426: @list = split(/\n/,$hash{'dirlist_files_'.$luri});
427: } else {
428: @list = &Apache::lonnet::dirlist($uri);
429: $hash{'dirlist_files_'.$luri} = join('\n',@list);
430: }
431: return @list=&match_ext($r,@list);
432: }
433:
434: # -------------------- filters out files based on extensions (returns an array)
435: sub match_ext {
436: my ($r,@packlist)=@_;
437: my @trimlist;
438: my $nextline;
439: my @fileext;
440: my $dirptr=16384;
441:
442: my $tabdir = $r->dir_config('lonTabDir');
443: my $fn = $tabdir.'/filetypes.tab';
444: if (-e $fn) {
445: my $FH=Apache::File->new($fn);
446: my @content=<$FH>;
447: foreach my $line (@content) {
448: (my $ext,my $foo) = split /\s+/,$line;
449: push @fileext,$ext;
450: }
451: }
452: foreach my $line (@packlist) {
453: chomp $line;
454: $line =~ s/^\/home\/httpd\/html//;
455: my @unpackline = split (/\&/,$line);
456: next if ($unpackline[0] eq ".");
457: next if ($unpackline[0] eq "..");
458: my @filecom = split (/\./,$unpackline[0]);
459: my $fext = pop(@filecom);
460: my $fnptr = $unpackline[3]&$dirptr;
461: if ($fnptr == 0 and $unpackline[3] ne "") {
462: foreach my $nextline (@fileext) {
463: push @trimlist,$line if $nextline eq $fext;
464: }
465: } else {
466: push @trimlist,$line;
467: }
468: }
469: @trimlist = sort (@trimlist);
470: return @trimlist;
471: }
472:
473: # ------------------------------- displays one line in appropriate table format
474: sub display_line{
475: my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
476: my (@pathfn, $fndir, $fnptr);
477: my $dirptr=16384;
478: my $fileclr="#ffffe6";
479: my $iconpath= $r->dir_config('lonIconsURL') . "/";
480:
481: my @filecom = split (/\&/,$line);
482: my @pathcom = split (/\//,$filecom[0]);
483: my $listname = $pathcom[scalar(@pathcom)-1];
484: my $fnptr = $filecom[3]&$dirptr;
485: my $msg = 'View '.$filecom[0].' resources';
486: $msg = 'Close '.$filecom[0].' directory' if $diropen eq "opened";
487:
488: my $tabtag="</td>";
489: my $i=0;
490:
491: while ($i<=5) {
492: $tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,"> </td>")
493: if $hash{'display_attrs_'.$i} == 1;
494: $i++;
495: }
496:
497: # display uplink arrow
498: if ($filecom[1] eq "viewOneUp") {
499: $r->print("<tr>$extrafield");
500: $r->print("<td bgcolor=$fileclr valign=bottom>\n");
501: $r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
502: '/" '.
503: 'onSubmit="return rep_dirpath(\'UP\','.
504: 'document.forms.fileattr.acts.value)" '.
505: 'enctype="application/x-www-form-urlencoded"'.
506: '>'."\n");
507: $r->print ('<input type=hidden name=openuri value="'.
508: $startdir.'">'."\n");
509: $r->print ('<input type="hidden" name="acts" value="">'."\n");
510: $r->print ('<input src="'.$iconpath.'arrow_up.gif"');
511: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
512: "\n");
513: $r->print("Up $tabtag</tr></form>\n");
514: return OK;
515: }
516:
517: # display domain
518: if ($filecom[1] eq "domain") {
519: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
520: if ($ENV{'form.dirPointer'} eq "on");
521: $r->print("<tr>$extrafield");
522: $r->print("<td bgcolor=$fileclr valign=bottom>");
523: &begin_form ($r,$filecom[0].'/');
524: my $anchor = $filecom[0].'/';
525: $anchor =~ s/\///g;
526: $r->print ('<a name="'.$anchor.'">');
527: $r->print ('<input type="hidden" name="acts" value="">');
528: $r->print ('<input src="'.$iconpath.'folder_pointer_'.
529: $diropen.'.gif"');
530: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
531: "\n");
532: $r->print ('<a href="javascript:gothere(\''.$filecom[0].
533: '/\')"><img src="'.$iconpath.'server.gif"');
534: $r->print (' border="0" /></a>'."\n");
535: $r->print("Domain - $listname $tabtag</tr></form>\n");
536: return OK;
537:
538: # display user directory
539: }
540: if ($filecom[1] eq "user") {
541: $r->print("<tr>$extrafield");
542: $r->print("<td bgcolor=$fileclr valign=bottom nowrap>\n");
543: my $curdir = $startdir.$filecom[0].'/';
544: my $anchor = $curdir;
545: $anchor =~ s/\///g;
546: &begin_form ($r,$curdir);
547: $r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
548: 'whitespace1.gif" border="0" />'."\n");
549: $r->print ('<input type="hidden" name="acts" value="">');
550: $r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
551: '.gif"');
552: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
553: "\n");
554: $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
555: $iconpath.'quill.gif border="0" name="'.$msg.
556: '" height="22" /></a>');
557: $r->print ($listname.$tabtag.'</tr></form>'."\n");
558: return OK;
559: }
560:
561: # display file
562: if ($fnptr == 0 and $filecom[3] ne "") {
563: my @file_ext = split (/\./,$listname);
564: my $curfext = $file_ext[scalar(@file_ext)-1];
565: my $filelink = $startdir.$filecom[0];
566: $r->print("<tr><td nowrap valign='bottom' bgcolor=$fileclr>");
567: my $metafile = grep /^$filecom[0]\.meta\&/, @list;
568: my $title;
569: if ($ENV{'form.catalogmode'} eq 'interactive') {
570: $title=$listname;
571: $title = &Apache::lonnet::metadata($filelink,'title')
572: if ($metafile == 1);
573: $title=$listname unless $title;
574: $r->print("<a href='javascript:select_data(\"",
575: $title,'","',$filelink,"\")'>");
576: $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
577: "\n");
578: $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
579: }
580: elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
581: $title=$listname;
582: $title = &Apache::lonnet::metadata($filelink,'title')
583: if ($metafile == 1);
584: $title=$listname unless $title;
585: $r->print("<form name='form$fnum'>\n");
586: $r->print("<input type='checkbox' name='filelink"."' ".
587: "value='$filelink' onClick='".
588: "javascript:queue(\"form$fnum\")' ");
589: if ($hash{'store_'.$filelink}) {
590: $r->print("checked");
591: }
592: $r->print(">\n");
593: $r->print("<input type='hidden' name='title"."' ".
594: "value='$title'>\n");
595: $r->print("</form>\n");
596: $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
597: $hash{"pre_${fnum}_link"}=$filelink;
598: $hash{"pre_${fnum}_title"}=$title;
599: $fnum++;
600: }
601:
602: if ($indent > 0 and $indent < 11) {
603: $r->print("<img src=",$iconpath,"whitespace",$indent,
604: ".gif border='0' />\n");
605: } elsif ($indent >0) {
606: my $ten = int($indent/10.);
607: my $rem = $indent%10.0;
608: my $count = 0;
609: while ($count < $ten) {
610: $r->print("<img src=",$iconpath,
611: "whitespace10.gif border='0' />\n");
612: $count++;
613: }
614: $r->print("<img src=",$iconpath,"whitespace",$rem,
615: ".gif border='0' />\n") if $rem > 0;
616: }
617:
618: $r->print("<img src=$iconpath$curfext.gif border='0' />\n");
619: $r->print (" <a href=\"javascript:openWindow('".$filelink.
620: "', 'metadatafile', '450', '500', 'no', 'yes')\";".
621: " TARGET=_self>$listname</a> ");
622:
623: $r->print (" (<a href=\"javascript:openWindow('".$filelink.
624: ".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; ".
625: "TARGET=_self>metadata</a>) ") if ($metafile == 1);
626:
627: $r->print("</td>\n");
628: $r->print("<td bgcolor=$fileclr align=right valign=bottom> ",
629: $filecom[8]," </td>\n")
630: if $hash{'display_attrs_0'} == 1;
631: $r->print("<td bgcolor=$fileclr valign=bottom> ".
632: (localtime($filecom[9]))." </td>\n")
633: if $hash{'display_attrs_1'} == 1;
634: $r->print("<td bgcolor=$fileclr valign=bottom> ".
635: (localtime($filecom[10]))." </td>\n")
636: if $hash{'display_attrs_2'} == 1;
637:
638: if ($hash{'display_attrs_3'} == 1) {
639: my $author = &Apache::lonnet::metadata($filelink,'author')
640: if ($metafile == 1);
641: $author = ' ' if (!$author);
642: $r->print("<td bgcolor=$fileclr valign=bottom> ".$author.
643: " </td>\n");
644: }
645: if ($hash{'display_attrs_4'} == 1) {
646: my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
647: if ($metafile == 1);
648: $keywords = ' ' if (!$keywords);
649: $r->print("<td bgcolor=$fileclr valign=bottom> ".$keywords.
650: " </td>\n");
651: }
652: if ($hash{'display_attrs_5'} == 1) {
653: my $lang = &Apache::lonnet::metadata($filelink,'language')
654: if ($metafile == 1);
655: $lang = $language{$lang};
656: $lang = ' ' if (!$lang);
657: $r->print("<td bgcolor=$fileclr valign=bottom> ".$lang.
658: " </td>\n");
659: }
660: $r->print("</tr>\n");
661: }
662:
663: # -- display directory
664: if ($fnptr == $dirptr) {
665: my @file_ext = split (/\./,$listname);
666: my $curfext = $file_ext[scalar(@file_ext)-1];
667: my $curdir = $startdir.$filecom[0].'/';
668: my $anchor = $curdir;
669: $anchor =~ s/\///g;
670: $r->print("<tr>$extrafield<td bgcolor=$fileclr valign=bottom>");
671: &begin_form ($r,$curdir);
672: my $indentm1 = $indent-1;
673: if ($indentm1 < 11 and $indentm1 > 0) {
674: $r->print("<img src=",$iconpath,"whitespace",$indentm1,
675: ".gif border='0' />\n");
676: } else {
677: my $ten = int($indentm1/10.);
678: my $rem = $indentm1%10.0;
679: my $count = 0;
680: while ($count < $ten) {
681: $r->print ("<img src=",$iconpath
682: ,"whitespace10.gif border='0' />\n");
683: $count++;
684: }
685: $r->print ("<img src=",$iconpath,"whitespace",$rem,
686: ".gif border='0' />\n") if $rem > 0;
687: }
688: $r->print ('<input type="hidden" name="acts" value="">');
689: $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
690: 'folder_pointer_'.$diropen.'.gif"');
691: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
692: "\n");
693: $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
694: $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
695: "\n");
696: $r->print ("$listname$tabtag</tr></form>\n");
697: }
698:
699: }
700:
701: # ------------------- prints the beginning of a form for directory or file link
702: sub begin_form {
703: my ($r,$uri) = @_;
704: my $anchor = $uri;
705: $anchor =~ s/\///g;
706: $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
707: '#'.$anchor.
708: '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
709: ',document.forms.fileattr.acts.value)" '.
710: 'enctype="application/x-www-form-urlencoded">'."\n");
711: $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
712: "\n");
713: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
714: $dnum++;
715: }
716:
717: # ----------- grab unprocessed CGI variables that may have been appended to URL
718: sub get_unprocessed_cgi {
719: map {
720: my ($name, $value) = split(/=/,$_);
721: $value =~ tr/+/ /;
722: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
723: if ($name eq 'catalogmode' or $name eq 'launch' or $name eq 'acts') {
724: $ENV{'form.'.$name}=$value;
725: }
726: } (split(/&/,$ENV{'QUERY_STRING'}));
727: }
728:
729: # --------- settings whenever the user causes the indexer window to be launched
730: sub start_fresh_session {
731: delete $hash{'mode_catalog'};
732: map {
733: if ($_ =~ /^pre_/) {
734: delete $hash{$_};
735: }
736: if ($_ =~ /^store/) {
737: delete $hash{$_};
738: }
739: } keys %hash;
740: }
741:
742: 1;
743: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>