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