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