Annotation of loncom/interface/lonindexer.pm, revision 1.38
1.1 www 1: # The LearningOnline Network with CAPA
1.24 harris41 2: # Directory Indexer
3: #
1.38 ! matthew 4: # $Id: lonindexer.pm,v 1.37 2002/03/08 18:33:29 matthew Exp $
1.24 harris41 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
1.14 harris41 14: #
1.24 harris41 15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
1.14 harris41 27: #
1.17 harris41 28: # YEAR=1999
29: # 5/21/99, 5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
1.1 www 30: # 11/23 Gerd Kortemeyer
1.17 harris41 31: # YEAR=2000
1.1 www 32: # 07/20-08/04 H.K. Ng
1.17 harris41 33: # YEAR=2001
1.2 harris41 34: # 05/9-05/19/2001 H. K. Ng
1.4 harris41 35: # 05/21/2001 H. K. Ng
1.6 harris41 36: # 05/23/2001 H. K. Ng
1.17 harris41 37: # 5/31,6/1,6/2,6/15 Scott Harrison
38: # 6/26,7/8 H. K. Ng
39: # 8/6,8/7,8/10 Scott Harrison
1.18 ng 40: # 8/14 H. K. Ng
1.24 harris41 41: # 8/28,10/15,11/28,11/29 Scott Harrison
1.25 matthew 42: # 11/30 Matthew Hall
1.28 harris41 43: # 12/11,12/13 Scott Harrison
1.32 harris41 44: # YEAR=2002
45: # 1/17 Scott Harrison
1.23 harris41 46: #
47: ###
48:
49: ###############################################################################
50: ## ##
51: ## ORGANIZATION OF THIS PERL MODULE ##
52: ## ##
53: ## 1. Description of functions ##
54: ## 2. Modules used by this module ##
55: ## 3. Choices for different output views (detailed, summary, xml, etc) ##
56: ## 4. BEGIN block (to be run once after compilation) ##
57: ## 5. Handling routine called via Apache and mod_perl ##
58: ## 6. Other subroutines ##
59: ## ##
60: ###############################################################################
1.7 harris41 61:
1.1 www 62: package Apache::lonindexer;
63:
1.23 harris41 64: # ------------------------------------------------- modules used by this module
1.1 www 65: use strict;
66: use Apache::lonnet();
1.30 harris41 67: use Apache::loncommon();
1.1 www 68: use Apache::Constants qw(:common);
1.2 harris41 69: use Apache::File;
70: use GDBM_File;
71:
1.23 harris41 72: # ---------------------------------------- variables used throughout the module
1.17 harris41 73: my %hash; # tied to a user-specific gdbm file
74: my %dirs; # keys are directories, values are the open/close status
75: my %language; # has the reference information present in language.tab
76:
77: # ----- Values which are set by the handler subroutine and are accessible to
78: # ----- other methods.
79: my $extrafield; # default extra table cell
80: my $fnum; # file counter
81: my $dnum; # directory counter
1.1 www 82:
1.23 harris41 83: # ----------------------------- Handling routine called via Apache and mod_perl
1.1 www 84: sub handler {
85: my $r = shift;
86: $r->content_type('text/html');
87: $r->send_http_header;
88: return OK if $r->header_only;
1.9 harris41 89: $fnum=0;
1.16 harris41 90: $dnum=0;
1.22 harris41 91: untie %hash;
1.17 harris41 92:
1.23 harris41 93: # ------------------------------------- read in machine configuration variables
1.10 harris41 94: my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.1 www 95: my $domain = $r->dir_config('lonDefDomain');
96: my $role = $r->dir_config('lonRole');
97: my $loadlim = $r->dir_config('lonLoadLim');
98: my $servadm = $r->dir_config('lonAdmEMail');
99: my $sysadm = $r->dir_config('lonSysEMail');
100: my $lonhost = $r->dir_config('lonHostID');
101: my $tabdir = $r->dir_config('lonTabDir');
102:
1.7 harris41 103: my $fileclr='#ffffe6';
1.15 harris41 104: my $line;
105: my (@attrchk,@openpath);
106: my $uri=$r->uri;
107:
1.7 harris41 108: # -------------------------------------- see if called from an interactive mode
1.35 matthew 109: # Get the parameters from the query string
1.36 matthew 110: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
111: ['catalogmode','launch','acts','mode','form','element']);
1.35 matthew 112: #-------------------------------------------------------------------
1.17 harris41 113: my $closebutton='';
1.7 harris41 114: my $groupimportbutton='';
115: my $colspan='';
1.14 harris41 116:
117: $extrafield='';
1.17 harris41 118: my $diropendb =
119: "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
1.15 harris41 120:
121: if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
122: if ($ENV{'form.launch'} eq '1') {
1.17 harris41 123: &start_fresh_session();
1.15 harris41 124: }
1.17 harris41 125:
126: # -------------------- refresh environment with user database values (in %hash)
1.15 harris41 127: if ($hash{'mode_catalog'} eq 'interactive') {
128: $ENV{'form.catalogmode'}='interactive';
129: }
130: if ($hash{'mode_catalog'} eq 'groupimport') {
131: $ENV{'form.catalogmode'}='groupimport';
132: }
133:
1.17 harris41 134: # --------------------- define extra fields and buttons in case of special mode
1.15 harris41 135: if ($ENV{'form.catalogmode'} eq 'interactive') {
136: $hash{'mode_catalog'}='interactive';
137: $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
138: '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17 harris41 139: ' border="0" /></td>';
1.15 harris41 140: $colspan=" colspan='2' ";
141: $closebutton=<<END;
1.7 harris41 142: <input type="button" name="close" value='CLOSE' onClick="self.close()">
143: END
1.16 harris41 144: }
1.15 harris41 145: elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
146: $hash{'mode_catalog'}='groupimport';
147: $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
148: '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17 harris41 149: ' border="0" /></td>';
1.15 harris41 150: $colspan=" colspan='2' ";
151: $closebutton=<<END;
1.7 harris41 152: <input type="button" name="close" value='CLOSE' onClick="self.close()">
153: END
1.15 harris41 154: $groupimportbutton=<<END;
1.17 harris41 155: <input type="button" name="groupimport" value='GROUP IMPORT'
156: onClick="javascript:select_group()">
1.7 harris41 157: END
1.15 harris41 158: }
1.35 matthew 159: # Additions made by Matthew to make the browser a little easier to deal
160: # with in the future.
161: #
162: # $mode (at this time) indicates if we are in edit mode.
163: # $form is the name of the form that the URL is placed when the
164: # selection is made.
165: # $element is the name of the element in $formname which receives
166: # the URL.
1.37 matthew 167: # &Apache::lonxml::debug('Checking mode, form, element');
1.35 matthew 168: &setvalues(\%hash,'form_mode' ,\%ENV,'form.mode' );
169: &setvalues(\%hash,'form_form' ,\%ENV,'form.form' );
170: &setvalues(\%hash,'form_element',\%ENV,'form.element');
171:
172: my $mode = $ENV{'form.mode'};
173: my ($form,$element);
174: if ($mode eq 'edit') {
175: $form = $ENV{'form.form'};
176: $element = $ENV{'form.element'};
177: }
178: &Apache::lonxml::debug("mode=$mode form=$form element=$element");
1.17 harris41 179: # ------ set catalogmodefunctions to have extra needed javascript functionality
1.15 harris41 180: my $catalogmodefunctions='';
181: if ($ENV{'form.catalogmode'} eq 'interactive' or
182: $ENV{'form.catalogmode'} eq 'groupimport') {
1.35 matthew 183: # The if statement below sets us up to use the old version
184: # by default (ie. if $mode is undefined). This is the easy
185: # way out. Hopefully in the future I'll find a way to get
186: # the calls dealt with in a more comprehensive manner.
187: if (!defined($mode) || $mode ne 'edit') {
188: $catalogmodefunctions=<<"END";
1.7 harris41 189: function select_data(title,url) {
190: changeTitle(title);
191: changeURL(url);
1.8 harris41 192: self.close();
193: }
194: function select_group() {
1.20 harris41 195: window.location="/adm/groupsort?catalogmode=groupimport&acts="+document.forms.fileattr.acts.value;
1.16 harris41 196: }
1.7 harris41 197: function changeTitle(val) {
1.35 matthew 198: if (opener.inf) {
199: if (opener.inf.document.forms.resinfo.elements.t) {
200: opener.inf.document.forms.resinfo.elements.t.value=val;
201: }
202: }
203: }
204: function changeURL(val) {
205: if (opener.inf) {
206: if (opener.inf.document.forms.resinfo.elements.u) {
207: opener.inf.document.forms.resinfo.elements.u.value=val;
208: }
1.7 harris41 209: }
210: }
1.35 matthew 211: END
212: } else { # we are in 'edit' mode
213: $catalogmodefunctions=<<END;
214: // mode = $mode
215: function select_data(title,url) {
216: changeURL(url);
217: self.close();
218: }
219:
220: function select_group() {
221: window.location="/adm/groupsort?catalogmode=interactive&form=$form&element=$element&mode=edit&acts="+document.forms.fileattr.acts.value;
222: }
223:
1.7 harris41 224: function changeURL(val) {
1.35 matthew 225: if (window.opener.document) {
226: window.opener.document.forms["$form"].elements["$element"].value=val;
227: } else {
228: alert("The file you selected is: "+val);
1.7 harris41 229: }
230: }
1.35 matthew 231:
1.7 harris41 232: END
1.35 matthew 233: }
1.15 harris41 234: }
1.38 ! matthew 235: $catalogmodefunctions.=<<END;
! 236: var acts='';
! 237: function rep_dirpath(suffix,val) {
! 238: eval("document.forms.dirpath"+suffix+".acts.value=val");
! 239: }
! 240: END
1.16 harris41 241: if ($ENV{'form.catalogmode'} eq 'groupimport') {
1.38 ! matthew 242: $catalogmodefunctions.=<<END;
1.16 harris41 243: function queue(val) {
244: if (eval("document.forms."+val+".filelink.checked")) {
245: var l=val.length;
246: var v=val.substring(4,l);
247: document.forms.fileattr.acts.value+='1a'+v+'b';
248: }
249: else {
250: var l=val.length;
251: var v=val.substring(4,l);
252: document.forms.fileattr.acts.value+='0a'+v+'b';
253: }
254: }
255: END
256: }
1.17 harris41 257:
1.1 www 258: # ---------------------------------------------------------------- Print Header
1.15 harris41 259: $r->print(<<ENDHEADER);
1.1 www 260: <html>
261: <head>
1.2 harris41 262: <title>The LearningOnline Network With CAPA Directory Browser</title>
1.3 harris41 263:
1.19 harris41 264: <script type="text/javascript">
1.7 harris41 265: $catalogmodefunctions
1.2 harris41 266: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
267: var options = "width=" + w + ",height=" + h + ",";
268: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
269: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
270: var newWin = window.open(url, wdwName, options);
271: newWin.focus();
272: }
1.16 harris41 273: function gothere(val) {
274: window.location=val+'?acts='+document.forms.fileattr.acts.value;
275: }
1.14 harris41 276: </script>
1.3 harris41 277:
1.1 www 278: </head>
279: <body bgcolor="#FFFFFF">
280: ENDHEADER
1.17 harris41 281:
282: # - Evaluate actions from previous page (both cumulatively and chronologically)
1.16 harris41 283: if ($ENV{'form.catalogmode'} eq 'groupimport') {
284: my $acts=$ENV{'form.acts'};
285: my @Acts=split(/b/,$acts);
286: my %ahash;
287: my %achash;
288: my $ac=0;
1.17 harris41 289: # some initial hashes for working with data
1.27 harris41 290: foreach (@Acts) {
1.16 harris41 291: my ($state,$ref)=split(/a/);
292: $ahash{$ref}=$state;
293: $achash{$ref}=$ac;
294: $ac++;
1.27 harris41 295: }
1.17 harris41 296: # sorting through the actions and changing the tied database hash
1.27 harris41 297: foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
1.16 harris41 298: my $key=$_;
299: if ($ahash{$key} eq '1') {
300: $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
301: $hash{'pre_'.$key.'_title'};
302: $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
303: $hash{'storectr'}+0;
304: $hash{'storectr'}++;
305: }
306: if ($ahash{$key} eq '0') {
307: if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
308: delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
309: }
310: }
1.27 harris41 311: }
1.17 harris41 312: # deleting the previously cached listing
1.27 harris41 313: foreach (keys %hash) {
1.16 harris41 314: if ($_ =~ /^pre_/ && $_ =~/link$/) {
315: my $key = $_;
316: $key =~ s/^pre_//;
317: $key =~ s/_[^_]*$//;
318: delete $hash{'pre_'.$key.'_title'};
319: delete $hash{'pre_'.$key.'_link'};
320: }
1.27 harris41 321: }
1.16 harris41 322: }
323:
1.23 harris41 324: # ---------------------------------------------------------------- output title
1.17 harris41 325: $r->print('<h2><font color="#888888">The LearningOnline With CAPA '.
326: 'Network Directory Browser</font></h2>'."\n");
1.23 harris41 327: # ---------------------------------- get state of file attributes to be showing
1.6 harris41 328: if ($ENV{'form.attrs'} ne "") {
1.18 ng 329: for (my $i=0; $i<=6; $i++) {
1.6 harris41 330: delete $hash{'display_attrs_'.$i};
331: if ($ENV{'form.attr'.$i} == 1) {
332: $attrchk[$i] = "checked";
333: $hash{'display_attrs_'.$i} = 1;
334: }
335: }
336: } else {
1.18 ng 337: for (my $i=0; $i<=6; $i++) {
1.6 harris41 338: $attrchk[$i] = "checked" if $hash{'display_attrs_'.$i} == 1;
339: }
340: }
1.23 harris41 341: # ------------------------------- output state of file attributes to be showing
1.15 harris41 342: $r->print(<<END);
1.17 harris41 343: <b><font color="#666666">Display file attributes</font></b><br />
344: <form method="post" name="fileattr" action="$uri"
345: enctype="application/x-www-form-urlencoded">
1.1 www 346: <table border=0><tr>
1.16 harris41 347: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] /> Size</td>
1.18 ng 348: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> Last access</td>
349: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> Last modified</td>
350: <td><input type="checkbox" name="attr6" value="1" $attrchk[6] /> All versions</td>
1.1 www 351: </tr><tr>
1.16 harris41 352: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> Author</td>
353: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> Keywords</td>
354: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> Language</td>
1.18 ng 355: <td> </td>
1.1 www 356: </tr></table>
1.16 harris41 357: <input type="hidden" name="dirPointer" value="on" />
358: <input type="hidden" name="acts" value="" />
359: <input type="submit" name="attrs" value="Review" />
360: <input type="submit" name="attrs" value="Refresh" />
1.7 harris41 361: $closebutton
362: $groupimportbutton
1.1 www 363: </form>
364: END
365:
1.23 harris41 366: # ----------------- output starting row to the indexed file/directory hierarchy
1.15 harris41 367: my $titleclr="#ddffff";
368: $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");
369: $r->print("<table border=0><tr>\n");
370: $r->print("<td $colspan bgcolor=$titleclr><b>Name</b></td>\n");
1.17 harris41 371: $r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) ".
372: "</b></td>\n") if ($hash{'display_attrs_0'} == 1);
373: $r->print("<td bgcolor=$titleclr><b>Last accessed</b></td>\n")
374: if ($hash{'display_attrs_1'} == 1);
375: $r->print("<td bgcolor=$titleclr><b>Last modified</b></td>\n")
376: if ($hash{'display_attrs_2'} == 1);
377: $r->print("<td bgcolor=$titleclr><b>Author(s)</b></td>\n")
378: if ($hash{'display_attrs_3'} == 1);
379: $r->print("<td bgcolor=$titleclr><b>Keywords</b></td>\n")
380: if ($hash{'display_attrs_4'} == 1);
381: $r->print("<td bgcolor=$titleclr><b>Language</b></td>\n")
382: if ($hash{'display_attrs_5'} == 1);
1.15 harris41 383: $r->print("</tr>");
1.5 harris41 384:
1.23 harris41 385: # ----------------- read in what directories have previously been set to "open"
1.27 harris41 386: foreach (keys %hash) {
1.4 harris41 387: if ($_ =~ /^diropen_status_/) {
388: my $key = $_;
389: $key =~ s/^diropen_status_//;
390: $dirs{$key} = $hash{$_};
391: }
1.27 harris41 392: }
1.4 harris41 393:
1.2 harris41 394: if ($ENV{'form.openuri'}) { # take care of review and refresh options
395: my $uri=$ENV{'form.openuri'};
1.4 harris41 396: if (exists($hash{'diropen_status_'.$uri})) {
397: my $cursta = $hash{'diropen_status_'.$uri};
1.2 harris41 398: $dirs{$uri} = 'open';
1.4 harris41 399: $hash{'diropen_status_'.$uri} = 'open';
400: if ($cursta eq 'open') {
401: $dirs{$uri} = 'closed';
402: $hash{'diropen_status_'.$uri} = 'closed';
403: }
1.2 harris41 404: } else {
1.4 harris41 405: $hash{'diropen_status_'.$uri} = 'open';
1.2 harris41 406: $dirs{$uri} = 'open';
407: }
408: }
1.12 ng 409:
410: my $bredir = $ENV{'form.dirPointer'};
411: my $toplevel;
1.13 ng 412: my $indent = 0;
1.12 ng 413: $uri = $uri.'/' if $uri !~ /.*\/$/;
1.17 harris41 414:
1.13 ng 415: if ($bredir ne "on") {
1.12 ng 416: $hash{'top.level'} = $uri;
417: $toplevel = $uri;
1.13 ng 418:
419: } else {
420: $toplevel = $hash{'top.level'};
421: }
1.17 harris41 422:
1.23 harris41 423: # -------------------------------- if not at top level, provide an uplink arrow
1.13 ng 424: if ($toplevel ne "/res/"){
425: my (@uri_com) = split(/\//,$uri);
426: pop @uri_com;
427: my $upone = join('/',@uri_com);
428: my @list = qw (0);
429: &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
430: $indent = 1;
1.12 ng 431: }
1.17 harris41 432:
1.23 harris41 433: # -------- recursively go through all the directories and output as appropriate
1.16 harris41 434: &scanDir ($r,$toplevel,$indent,\%hash);
1.12 ng 435:
1.23 harris41 436: # ---------------------------- embed hidden information useful for group import
1.8 harris41 437: $r->print("<form name='fnum'>");
438: $r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
1.17 harris41 439:
1.23 harris41 440: # -------------------------------------------------------------- end the tables
1.2 harris41 441: $r->print("</table>");
442: $r->print("</td></tr></table>");
1.17 harris41 443:
1.23 harris41 444: # --------------------------------------------------- end the output and return
1.2 harris41 445: $r->print("</body></html>\n");
1.4 harris41 446: untie(%hash);
1.2 harris41 447: } else {
1.17 harris41 448: $r->print('<html><head></head><body>Unable to tie hash to db '.
449: 'file</body></html>');
450: return OK;
1.2 harris41 451: }
1.1 www 452: return OK;
453: }
1.2 harris41 454:
1.17 harris41 455: # ----------------------------------------------- recursive scan of a directory
1.2 harris41 456: sub scanDir {
1.16 harris41 457: my ($r,$startdir,$indent,$hashref)=@_;
1.3 harris41 458: my ($compuri,$curdir);
459: my $dirptr=16384;
1.1 www 460: $indent++;
461:
1.2 harris41 462: my %dupdirs = %dirs;
463: my @list=&get_list($r,$startdir);
464: foreach my $line (@list) {
1.5 harris41 465: my ($strip,$dom,$foo,$testdir,$foo)=split(/\&/,$line,5);
1.4 harris41 466: next if $strip =~ /.*\.meta$/;
1.18 ng 467: my (@fileparts) = split(/\./,$strip);
468: if ($hash{'display_attrs_6'} != 1) {
469: if (scalar(@fileparts) >= 3) {
470: my $fext = pop @fileparts;
471: my $ov = pop @fileparts;
472: my $fname = join ('.',@fileparts,$fext);
473: next if (grep /$fname/,@list and $ov =~ /\d+/);
474: }
475: }
476:
1.5 harris41 477: if ($dom eq "domain") {
1.17 harris41 478: $compuri = join('',$strip,"/"); # dom list has /res/<domain name>
1.3 harris41 479: $curdir = $compuri;
1.2 harris41 480: } else {
1.17 harris41 481: # user, dir & file have name only, i.e., w/o path
482: $compuri = join('',$startdir,$strip,"/");
1.3 harris41 483: $curdir = $startdir;
1.2 harris41 484: }
1.11 ng 485: my $diropen = "closed";
1.5 harris41 486: if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/)) {
1.3 harris41 487: while (my ($key,$val)= each %dupdirs) {
1.5 harris41 488: if ($key eq $compuri and $val eq "open") {
1.11 ng 489: $diropen = "opened";
1.5 harris41 490: delete $dupdirs{key},$dirs{$key};
491: }
1.3 harris41 492: }
1.1 www 493: }
1.16 harris41 494: &display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
1.11 ng 495: &scanDir ($r,$compuri,$indent) if $diropen eq "opened";
1.1 www 496: }
497: $indent--;
498: }
499:
1.17 harris41 500: # --------------- get complete matched list based on the uri (returns an array)
1.1 www 501: sub get_list {
502: my ($r,$uri)=@_;
503: my @list;
1.2 harris41 504: my $luri = $uri;
505: $luri =~ s/\//_/g;
506:
1.6 harris41 507: if ($ENV{'form.attrs'} eq "Refresh") {
1.27 harris41 508: foreach (keys %hash) {
1.4 harris41 509: delete $hash{$_} if ($_ =~ /^dirlist_files_/);
1.27 harris41 510: }
1.2 harris41 511: }
512:
1.4 harris41 513: if ($hash{'dirlist_files'.$luri}) {
514: @list = split(/\n/,$hash{'dirlist_files_'.$luri});
1.1 www 515: } else {
1.4 harris41 516: @list = &Apache::lonnet::dirlist($uri);
517: $hash{'dirlist_files_'.$luri} = join('\n',@list);
1.1 www 518: }
519: return @list=&match_ext($r,@list);
520: }
521:
1.17 harris41 522: # -------------------- filters out files based on extensions (returns an array)
1.1 www 523: sub match_ext {
524: my ($r,@packlist)=@_;
525: my @trimlist;
526: my $nextline;
527: my @fileext;
528: my $dirptr=16384;
529:
1.2 harris41 530: foreach my $line (@packlist) {
531: chomp $line;
532: $line =~ s/^\/home\/httpd\/html//;
533: my @unpackline = split (/\&/,$line);
534: next if ($unpackline[0] eq ".");
535: next if ($unpackline[0] eq "..");
536: my @filecom = split (/\./,$unpackline[0]);
537: my $fext = pop(@filecom);
538: my $fnptr = $unpackline[3]&$dirptr;
539: if ($fnptr == 0 and $unpackline[3] ne "") {
1.28 harris41 540: my $embstyle = &Apache::loncommon::fileembstyle($fext);
1.25 matthew 541: push @trimlist,$line if (defined($embstyle) &&
1.32 harris41 542: ($embstyle ne 'hdn' or $fext eq 'meta'));
1.1 www 543: } else {
1.2 harris41 544: push @trimlist,$line;
1.1 www 545: }
546: }
1.4 harris41 547: @trimlist = sort (@trimlist);
1.1 www 548: return @trimlist;
549: }
550:
1.17 harris41 551: # ------------------------------- displays one line in appropriate table format
1.23 harris41 552: sub display_line {
1.16 harris41 553: my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
1.1 www 554: my (@pathfn, $fndir, $fnptr);
555: my $dirptr=16384;
556: my $fileclr="#ffffe6";
1.10 harris41 557: my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.1 www 558:
559: my @filecom = split (/\&/,$line);
560: my @pathcom = split (/\//,$filecom[0]);
561: my $listname = $pathcom[scalar(@pathcom)-1];
562: my $fnptr = $filecom[3]&$dirptr;
1.4 harris41 563: my $msg = 'View '.$filecom[0].' resources';
1.11 ng 564: $msg = 'Close '.$filecom[0].' directory' if $diropen eq "opened";
1.1 www 565:
566: my $tabtag="</td>";
567: my $i=0;
568:
569: while ($i<=5) {
1.17 harris41 570: $tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,"> </td>")
571: if $hash{'display_attrs_'.$i} == 1;
1.1 www 572: $i++;
573: }
1.17 harris41 574:
575: # display uplink arrow
1.13 ng 576: if ($filecom[1] eq "viewOneUp") {
577: $r->print("<tr>$extrafield");
578: $r->print("<td bgcolor=$fileclr valign=bottom>\n");
1.16 harris41 579: $r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
580: '/" '.
1.17 harris41 581: 'onSubmit="return rep_dirpath(\'UP\','.
582: 'document.forms.fileattr.acts.value)" '.
1.16 harris41 583: 'enctype="application/x-www-form-urlencoded"'.
584: '>'."\n");
1.17 harris41 585: $r->print ('<input type=hidden name=openuri value="'.
586: $startdir.'">'."\n");
1.16 harris41 587: $r->print ('<input type="hidden" name="acts" value="">'."\n");
1.13 ng 588: $r->print ('<input src="'.$iconpath.'arrow_up.gif"');
1.17 harris41 589: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
590: "\n");
1.13 ng 591: $r->print("Up $tabtag</tr></form>\n");
592: return OK;
593: }
1.17 harris41 594:
595: # display domain
1.1 www 596: if ($filecom[1] eq "domain") {
1.17 harris41 597: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
598: if ($ENV{'form.dirPointer'} eq "on");
1.7 harris41 599: $r->print("<tr>$extrafield");
1.1 www 600: $r->print("<td bgcolor=$fileclr valign=bottom>");
1.2 harris41 601: &begin_form ($r,$filecom[0].'/');
1.3 harris41 602: my $anchor = $filecom[0].'/';
603: $anchor =~ s/\///g;
1.13 ng 604: $r->print ('<a name="'.$anchor.'">');
1.16 harris41 605: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 606: $r->print ('<input src="'.$iconpath.'folder_pointer_'.
607: $diropen.'.gif"');
608: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
609: "\n");
610: $r->print ('<a href="javascript:gothere(\''.$filecom[0].
611: '/\')"><img src="'.$iconpath.'server.gif"');
612: $r->print (' border="0" /></a>'."\n");
1.1 www 613: $r->print("Domain - $listname $tabtag</tr></form>\n");
614: return OK;
1.17 harris41 615:
616: # display user directory
1.1 www 617: }
618: if ($filecom[1] eq "user") {
1.7 harris41 619: $r->print("<tr>$extrafield");
1.13 ng 620: $r->print("<td bgcolor=$fileclr valign=bottom nowrap>\n");
1.2 harris41 621: my $curdir = $startdir.$filecom[0].'/';
1.3 harris41 622: my $anchor = $curdir;
623: $anchor =~ s/\///g;
1.13 ng 624: &begin_form ($r,$curdir);
1.17 harris41 625: $r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
626: 'whitespace1.gif" border="0" />'."\n");
1.16 harris41 627: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 628: $r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
629: '.gif"');
630: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
631: "\n");
632: $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
633: $iconpath.'quill.gif border="0" name="'.$msg.
634: '" height="22" /></a>');
1.13 ng 635: $r->print ($listname.$tabtag.'</tr></form>'."\n");
1.1 www 636: return OK;
637: }
1.17 harris41 638:
1.1 www 639: # display file
640: if ($fnptr == 0 and $filecom[3] ne "") {
641: my @file_ext = split (/\./,$listname);
1.25 matthew 642: my $curfext = $file_ext[-1];
643: # Set the icon for the file
1.26 matthew 644: my $iconname = "unknown.gif";
1.28 harris41 645: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.25 matthew 646: # The unless conditional that follows is a bit of overkill
647: $iconname = $curfext.".gif" unless
1.26 matthew 648: (!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn');
1.25 matthew 649: #
1.2 harris41 650: my $filelink = $startdir.$filecom[0];
1.8 harris41 651: $r->print("<tr><td nowrap valign='bottom' bgcolor=$fileclr>");
1.7 harris41 652: my $metafile = grep /^$filecom[0]\.meta\&/, @list;
653: my $title;
654: if ($ENV{'form.catalogmode'} eq 'interactive') {
655: $title=$listname;
1.8 harris41 656: $title = &Apache::lonnet::metadata($filelink,'title')
657: if ($metafile == 1);
1.7 harris41 658: $title=$listname unless $title;
1.33 harris41 659: my $titleesc=$title;
1.35 matthew 660: $titleesc=~s/\'/\\'/; #' (clean up this spare quote
661: $r->print("<a href=\"javascript:select_data(\'",
1.34 harris41 662: $titleesc,"','",$filelink,"')\">");
1.17 harris41 663: $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
664: "\n");
1.8 harris41 665: $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
666: }
667: elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
668: $title=$listname;
669: $title = &Apache::lonnet::metadata($filelink,'title')
670: if ($metafile == 1);
671: $title=$listname unless $title;
672: $r->print("<form name='form$fnum'>\n");
673: $r->print("<input type='checkbox' name='filelink"."' ".
1.16 harris41 674: "value='$filelink' onClick='".
675: "javascript:queue(\"form$fnum\")' ");
676: if ($hash{'store_'.$filelink}) {
677: $r->print("checked");
678: }
679: $r->print(">\n");
1.8 harris41 680: $r->print("<input type='hidden' name='title"."' ".
681: "value='$title'>\n");
682: $r->print("</form>\n");
683: $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
1.16 harris41 684: $hash{"pre_${fnum}_link"}=$filelink;
685: $hash{"pre_${fnum}_title"}=$title;
1.8 harris41 686: $fnum++;
1.7 harris41 687: }
1.4 harris41 688:
1.12 ng 689: if ($indent > 0 and $indent < 11) {
1.17 harris41 690: $r->print("<img src=",$iconpath,"whitespace",$indent,
691: ".gif border='0' />\n");
1.11 ng 692: } elsif ($indent >0) {
1.4 harris41 693: my $ten = int($indent/10.);
694: my $rem = $indent%10.0;
695: my $count = 0;
696: while ($count < $ten) {
1.17 harris41 697: $r->print("<img src=",$iconpath,
698: "whitespace10.gif border='0' />\n");
1.1 www 699: $count++;
1.4 harris41 700: }
1.17 harris41 701: $r->print("<img src=",$iconpath,"whitespace",$rem,
702: ".gif border='0' />\n") if $rem > 0;
1.1 www 703: }
1.4 harris41 704:
1.25 matthew 705: $r->print("<img src=$iconpath$iconname border='0' />\n");
1.17 harris41 706: $r->print (" <a href=\"javascript:openWindow('".$filelink.
707: "', 'metadatafile', '450', '500', 'no', 'yes')\";".
708: " TARGET=_self>$listname</a> ");
709:
710: $r->print (" (<a href=\"javascript:openWindow('".$filelink.
711: ".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; ".
712: "TARGET=_self>metadata</a>) ") if ($metafile == 1);
1.2 harris41 713:
1.7 harris41 714: $r->print("</td>\n");
1.17 harris41 715: $r->print("<td bgcolor=$fileclr align=right valign=bottom> ",
716: $filecom[8]," </td>\n")
1.11 ng 717: if $hash{'display_attrs_0'} == 1;
1.17 harris41 718: $r->print("<td bgcolor=$fileclr valign=bottom> ".
719: (localtime($filecom[9]))." </td>\n")
1.11 ng 720: if $hash{'display_attrs_1'} == 1;
1.17 harris41 721: $r->print("<td bgcolor=$fileclr valign=bottom> ".
722: (localtime($filecom[10]))." </td>\n")
1.11 ng 723: if $hash{'display_attrs_2'} == 1;
1.2 harris41 724:
1.6 harris41 725: if ($hash{'display_attrs_3'} == 1) {
1.17 harris41 726: my $author = &Apache::lonnet::metadata($filelink,'author')
727: if ($metafile == 1);
1.2 harris41 728: $author = ' ' if (!$author);
1.17 harris41 729: $r->print("<td bgcolor=$fileclr valign=bottom> ".$author.
730: " </td>\n");
1.2 harris41 731: }
1.6 harris41 732: if ($hash{'display_attrs_4'} == 1) {
1.17 harris41 733: my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
734: if ($metafile == 1);
1.2 harris41 735: $keywords = ' ' if (!$keywords);
1.17 harris41 736: $r->print("<td bgcolor=$fileclr valign=bottom> ".$keywords.
737: " </td>\n");
1.2 harris41 738: }
1.6 harris41 739: if ($hash{'display_attrs_5'} == 1) {
1.17 harris41 740: my $lang = &Apache::lonnet::metadata($filelink,'language')
741: if ($metafile == 1);
1.28 harris41 742: $lang = &Apache::loncommon::languagedescription($lang);
1.2 harris41 743: $lang = ' ' if (!$lang);
1.17 harris41 744: $r->print("<td bgcolor=$fileclr valign=bottom> ".$lang.
745: " </td>\n");
1.2 harris41 746: }
1.1 www 747: $r->print("</tr>\n");
748: }
1.17 harris41 749:
1.2 harris41 750: # -- display directory
1.1 www 751: if ($fnptr == $dirptr) {
752: my @file_ext = split (/\./,$listname);
753: my $curfext = $file_ext[scalar(@file_ext)-1];
1.2 harris41 754: my $curdir = $startdir.$filecom[0].'/';
1.3 harris41 755: my $anchor = $curdir;
756: $anchor =~ s/\///g;
1.7 harris41 757: $r->print("<tr>$extrafield<td bgcolor=$fileclr valign=bottom>");
1.2 harris41 758: &begin_form ($r,$curdir);
1.4 harris41 759: my $indentm1 = $indent-1;
1.11 ng 760: if ($indentm1 < 11 and $indentm1 > 0) {
1.17 harris41 761: $r->print("<img src=",$iconpath,"whitespace",$indentm1,
762: ".gif border='0' />\n");
1.4 harris41 763: } else {
764: my $ten = int($indentm1/10.);
765: my $rem = $indentm1%10.0;
766: my $count = 0;
767: while ($count < $ten) {
1.17 harris41 768: $r->print ("<img src=",$iconpath
769: ,"whitespace10.gif border='0' />\n");
1.12 ng 770: $count++;
1.4 harris41 771: }
1.17 harris41 772: $r->print ("<img src=",$iconpath,"whitespace",$rem,
773: ".gif border='0' />\n") if $rem > 0;
1.1 www 774: }
1.16 harris41 775: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 776: $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
777: 'folder_pointer_'.$diropen.'.gif"');
778: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
779: "\n");
780: $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
781: $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
782: "\n");
1.13 ng 783: $r->print ("$listname$tabtag</tr></form>\n");
1.1 www 784: }
1.2 harris41 785:
1.1 www 786: }
787:
1.14 harris41 788: # ------------------- prints the beginning of a form for directory or file link
1.1 www 789: sub begin_form {
790: my ($r,$uri) = @_;
1.3 harris41 791: my $anchor = $uri;
792: $anchor =~ s/\///g;
1.17 harris41 793: $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
794: '#'.$anchor.
795: '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
796: ',document.forms.fileattr.acts.value)" '.
1.16 harris41 797: 'enctype="application/x-www-form-urlencoded">'."\n");
1.17 harris41 798: $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
799: "\n");
800: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
1.16 harris41 801: $dnum++;
1.17 harris41 802: }
803:
804: # --------- settings whenever the user causes the indexer window to be launched
805: sub start_fresh_session {
806: delete $hash{'mode_catalog'};
1.35 matthew 807: delete $hash{'form_mode'};
808: delete $hash{'form_form'};
809: delete $hash{'form_element'};
1.27 harris41 810: foreach (keys %hash) {
1.17 harris41 811: if ($_ =~ /^pre_/) {
812: delete $hash{$_};
813: }
814: if ($_ =~ /^store/) {
815: delete $hash{$_};
816: }
1.27 harris41 817: }
1.1 www 818: }
819:
1.35 matthew 820: # ------------------------------------------------------------------- setvalues
821: sub setvalues {
822: # setvalues is used in registerurl to synchronize the database
823: # hash and environment hashes
824: my ($H1,$h1key,$H2,$h2key) =@_;
825: #
826: if (exists $H2->{$h2key}) {
827: $H1->{$h1key} = $H2->{$h2key};
828: } elsif (exists $H1->{$h1key}) {
829: $H2->{$h2key} = $H1->{$h1key};
830: }
831: }
832:
1.1 www 833: 1;
1.23 harris41 834:
835: =head1 NAME
836:
837: Apache::lonindexer - mod_perl module for cross server filesystem browsing
838:
839: =head1 SYNOPSIS
840:
841: Invoked by /etc/httpd/conf/srm.conf:
842:
843: <LocationMatch "^/res.*/$">
844: SetHandler perl-script
845: PerlHandler Apache::lonindexer
846: </LocationMatch>
847:
848: =head1 INTRODUCTION
849:
850: This module enables a scheme of browsing across a cross server.
851:
852: This is part of the LearningOnline Network with CAPA project
853: described at http://www.lon-capa.org.
854:
855: =head1 BEGIN SUBROUTINE
856:
857: This routine is only run once after compilation.
858:
859: =over 4
860:
861: =item *
862:
863: Initializes %language hash table.
864:
865: =back
866:
867: =head1 HANDLER SUBROUTINE
868:
869: This routine is called by Apache and mod_perl.
870:
871: =over 4
872:
873: =item *
874:
875: read in machine configuration variables
876:
877: =item *
878:
879: see if called from an interactive mode
880:
881: =item *
882:
883: refresh environment with user database values (in %hash)
884:
885: =item *
886:
887: define extra fields and buttons in case of special mode
888:
889: =item *
890:
891: set catalogmodefunctions to have extra needed javascript functionality
892:
893: =item *
894:
895: print header
896:
897: =item *
898:
899: evaluate actions from previous page (both cumulatively and chronologically)
900:
901: =item *
902:
903: output title
904:
905: =item *
906:
907: get state of file attributes to be showing
908:
909: =item *
910:
911: output state of file attributes to be showing
912:
913: =item *
914:
915: output starting row to the indexed file/directory hierarchy
916:
917: =item *
918:
919: read in what directories have previously been set to "open"
920:
921: =item *
922:
923: if not at top level, provide an uplink arrow
924:
925: =item *
926:
927: recursively go through all the directories and output as appropriate
928:
929: =item *
930:
931: information useful for group import
932:
933: =item *
934:
935: end the tables
936:
937: =item *
938:
939: end the output and return
940:
941: =back
942:
943: =head1 OTHER SUBROUTINES
944:
945: =over 4
946:
947: =item *
948:
949: scanDir - recursive scan of a directory
950:
951: =item *
952:
953: get_list - get complete matched list based on the uri (returns an array)
954:
955: =item *
956:
957: match_ext - filters out files based on extensions (returns an array)
958:
959: =item *
960:
961: display_line - displays one line in appropriate table format
962:
963: =item *
964:
965: begin_form - prints the beginning of a form for directory or file link
966:
967: =item *
968:
969: start_fresh_session - settings whenever the user causes the indexer window
970: to be launched
971:
972: =back
973:
974: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>