Annotation of loncom/interface/lonindexer.pm, revision 1.111
1.1 www 1: # The LearningOnline Network with CAPA
1.24 harris41 2: # Directory Indexer
3: #
1.111 ! www 4: # $Id: lonindexer.pm,v 1.110 2004/06/12 04:44:31 albertel 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.23 harris41 28: ###
29:
30: ###############################################################################
31: ## ##
32: ## ORGANIZATION OF THIS PERL MODULE ##
33: ## ##
34: ## 1. Description of functions ##
35: ## 2. Modules used by this module ##
36: ## 3. Choices for different output views (detailed, summary, xml, etc) ##
37: ## 4. BEGIN block (to be run once after compilation) ##
38: ## 5. Handling routine called via Apache and mod_perl ##
39: ## 6. Other subroutines ##
40: ## ##
41: ###############################################################################
1.7 harris41 42:
1.1 www 43: package Apache::lonindexer;
44:
1.23 harris41 45: # ------------------------------------------------- modules used by this module
1.1 www 46: use strict;
47: use Apache::lonnet();
1.30 harris41 48: use Apache::loncommon();
1.83 www 49: use Apache::lonhtmlcommon();
1.94 www 50: use Apache::lonsequence();
1.1 www 51: use Apache::Constants qw(:common);
1.70 ng 52: use Apache::lonmeta;
1.2 harris41 53: use Apache::File;
1.77 www 54: use Apache::lonlocal;
1.109 taceyjo1 55: use Apache::lonsource();
1.111 ! www 56: use LONCAPA::lonmetadata();
1.2 harris41 57: use GDBM_File;
58:
1.23 harris41 59: # ---------------------------------------- variables used throughout the module
1.87 www 60: my %hash; # global user-specific gdbm file
1.17 harris41 61: my %dirs; # keys are directories, values are the open/close status
62: my %language; # has the reference information present in language.tab
1.111 ! www 63: my %dynhash; # hash of hashes for dynamic metadata
1.17 harris41 64:
65: # ----- Values which are set by the handler subroutine and are accessible to
66: # ----- other methods.
67: my $extrafield; # default extra table cell
68: my $fnum; # file counter
69: my $dnum; # directory counter
1.1 www 70:
1.40 matthew 71: # ----- Used to include or exclude files with certain extensions.
1.43 matthew 72: my @Only = ();
1.40 matthew 73: my @Omit = ();
74:
75:
1.23 harris41 76: # ----------------------------- Handling routine called via Apache and mod_perl
1.1 www 77: sub handler {
78: my $r = shift;
1.67 matthew 79: my $c = $r->connection();
1.76 www 80: &Apache::loncommon::content_type($r,'text/html');
1.50 albertel 81: &Apache::loncommon::no_cache($r);
1.1 www 82: $r->send_http_header;
83: return OK if $r->header_only;
1.9 harris41 84: $fnum=0;
1.16 harris41 85: $dnum=0;
1.17 harris41 86:
1.43 matthew 87: # Deal with stupid global variables (is there a way around making
88: # these global to this package? It is just so wrong....)
89: undef (@Only);
90: undef (@Omit);
91:
1.23 harris41 92: # ------------------------------------- read in machine configuration variables
1.10 harris41 93: my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.1 www 94: my $domain = $r->dir_config('lonDefDomain');
95: my $role = $r->dir_config('lonRole');
96: my $loadlim = $r->dir_config('lonLoadLim');
97: my $servadm = $r->dir_config('lonAdmEMail');
98: my $sysadm = $r->dir_config('lonSysEMail');
99: my $lonhost = $r->dir_config('lonHostID');
100: my $tabdir = $r->dir_config('lonTabDir');
101:
1.7 harris41 102: my $fileclr='#ffffe6';
1.15 harris41 103: my $line;
104: my (@attrchk,@openpath);
105: my $uri=$r->uri;
106:
1.7 harris41 107: # -------------------------------------- see if called from an interactive mode
1.35 matthew 108: # Get the parameters from the query string
1.36 matthew 109: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.40 matthew 110: ['catalogmode','launch','acts','mode','form','element',
1.79 albertel 111: 'only','omit','titleelement']);
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 =
1.66 albertel 119: "/home/httpd/perl/tmp/$ENV{'user.domain'}_$ENV{'user.name'}_indexer.db";
1.67 matthew 120: %hash = ();
1.68 albertel 121: {
122: my %dbfile;
1.87 www 123: if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_READER(),0640)) {
1.68 albertel 124: while(my($key,$value)=each(%dbfile)) {
125: $hash{$key}=$value;
126: }
127: untie(%dbfile);
128: }
129: }
130: {
1.15 harris41 131: if ($ENV{'form.launch'} eq '1') {
1.17 harris41 132: &start_fresh_session();
1.105 taceyjo1 133: }
134: #Hijack lonindexer to verify a title and be close down.
135: if ($ENV{'form.launch'} eq '2') {
1.108 albertel 136: $r->content_type('text/html');
137: my $extra='';
138: if (defined($ENV{'form.titleelement'})) {
139: my $verify_title = &Apache::lonnet::gettitle($ENV{'form.acts'});
140: &Apache::lonnet::logthis("Hrrm $ENV{'form.acts'} -- $verify_title");
141: $verify_title=~s/'/\\'/g;
142: $extra='window.opener.document.forms["'.$ENV{'form.form'}.'"].elements["'.$ENV{'form.titleelement'}.'"].value=\''.$verify_title.'\';';
143: }
144: $r->print(<<ENDSUBM);
1.105 taceyjo1 145: <html>
146: <script type="text/javascript">
147: function load() {
148: window.opener.document.forms["$ENV{'form.form'}"].elements["$ENV{'form.element'}"].value='$ENV{'form.acts'}';
1.108 albertel 149: $extra
1.105 taceyjo1 150: window.close();
151: }
152: </script>
153: <body onLoad=load();>
154: </body>
155: </html>
156: ENDSUBM
1.108 albertel 157: return OK;
1.105 taceyjo1 158: }
159:
1.17 harris41 160: # -------------------- refresh environment with user database values (in %hash)
1.48 matthew 161: &setvalues(\%hash,'form.catalogmode',\%ENV,'form.catalogmode' );
1.15 harris41 162:
1.17 harris41 163: # --------------------- define extra fields and buttons in case of special mode
1.15 harris41 164: if ($ENV{'form.catalogmode'} eq 'interactive') {
165: $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
166: '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17 harris41 167: ' border="0" /></td>';
1.15 harris41 168: $colspan=" colspan='2' ";
1.77 www 169: my $cl=&mt('Close');
1.15 harris41 170: $closebutton=<<END;
1.77 www 171: <input type="button" name="close" value='$cl' onClick="self.close()">
1.7 harris41 172: END
1.16 harris41 173: }
1.15 harris41 174: elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
175: $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
176: '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17 harris41 177: ' border="0" /></td>';
1.15 harris41 178: $colspan=" colspan='2' ";
1.77 www 179: my $cl=&mt('Close');
180: my $gi=&mt('Group Import');
1.15 harris41 181: $closebutton=<<END;
1.77 www 182: <input type="button" name="close" value='$cl' onClick="self.close()">
1.7 harris41 183: END
1.15 harris41 184: $groupimportbutton=<<END;
1.77 www 185: <input type="button" name="groupimport" value='$gi'
1.17 harris41 186: onClick="javascript:select_group()">
1.7 harris41 187: END
1.15 harris41 188: }
1.35 matthew 189: # Additions made by Matthew to make the browser a little easier to deal
190: # with in the future.
191: #
192: # $mode (at this time) indicates if we are in edit mode.
193: # $form is the name of the form that the URL is placed when the
194: # selection is made.
195: # $element is the name of the element in $formname which receives
196: # the URL.
1.91 taceyjo1 197: #&Apache::lonxml::debug('Checking mode, form, element');
1.79 albertel 198: &setvalues(\%hash,'form.mode' ,\%ENV,'form.mode' );
199: &setvalues(\%hash,'form.form' ,\%ENV,'form.form' );
200: &setvalues(\%hash,'form.element' ,\%ENV,'form.element');
201: &setvalues(\%hash,'form.titleelement',\%ENV,'form.titleelement');
202: &setvalues(\%hash,'form.only' ,\%ENV,'form.only' );
203: &setvalues(\%hash,'form.omit' ,\%ENV,'form.omit' );
1.35 matthew 204:
1.40 matthew 205: # Deal with 'omit' and 'only'
206: if (exists $ENV{'form.omit'}) {
207: @Omit = split(',',$ENV{'form.omit'});
208: }
209: if (exists $ENV{'form.only'}) {
210: @Only = split(',',$ENV{'form.only'});
211: }
212:
1.35 matthew 213: my $mode = $ENV{'form.mode'};
1.79 albertel 214: my ($form,$element,$titleelement);
1.39 matthew 215: if ($mode eq 'edit' || $mode eq 'parmset') {
1.79 albertel 216: $form = $ENV{'form.form'};
217: $element = $ENV{'form.element'};
218: $titleelement = $ENV{'form.titleelement'};
1.35 matthew 219: }
1.90 taceyjo1 220: #&Apache::lonxml::debug("mode=$mode form=$form element=$element titleelement=$titleelement");
1.17 harris41 221: # ------ set catalogmodefunctions to have extra needed javascript functionality
1.15 harris41 222: my $catalogmodefunctions='';
223: if ($ENV{'form.catalogmode'} eq 'interactive' or
224: $ENV{'form.catalogmode'} eq 'groupimport') {
1.35 matthew 225: # The if statement below sets us up to use the old version
226: # by default (ie. if $mode is undefined). This is the easy
227: # way out. Hopefully in the future I'll find a way to get
228: # the calls dealt with in a more comprehensive manner.
1.41 www 229:
230: #
231: # There is now also mode "simple", which is for the simple version of the rat
232: #
233: #
1.39 matthew 234: if (!defined($mode) || ($mode ne 'edit' && $mode ne 'parmset')) {
1.40 matthew 235: my $location = "/adm/groupsort?catalogmode=groupimport&";
1.41 www 236: $location .= "mode=".$mode."&";
1.40 matthew 237: $location .= "acts=";
1.35 matthew 238: $catalogmodefunctions=<<"END";
1.108 albertel 239: function select_data(url) {
1.7 harris41 240: changeURL(url);
1.8 harris41 241: self.close();
242: }
243: function select_group() {
1.40 matthew 244: window.location="$location"+document.forms.fileattr.acts.value;
1.16 harris41 245: }
1.35 matthew 246: function changeURL(val) {
247: if (opener.inf) {
248: if (opener.inf.document.forms.resinfo.elements.u) {
249: opener.inf.document.forms.resinfo.elements.u.value=val;
250: }
1.7 harris41 251: }
252: }
1.35 matthew 253: END
1.39 matthew 254: } elsif ($mode eq 'edit') { # we are in 'edit' mode
1.40 matthew 255: my $location = "/adm/groupsort?catalogmode=interactive&";
256: $location .= "form=$form&element=$element&mode=edit&acts=";
1.35 matthew 257: $catalogmodefunctions=<<END;
258: // mode = $mode
1.108 albertel 259: function select_data(url) {
260: var location = "/res/?launch=2&form=$form&element=$element&titleelement=$titleelement&acts=" + url;
1.105 taceyjo1 261: window.location=location;
1.35 matthew 262: }
263: function select_group() {
1.40 matthew 264: window.location="$location"+document.forms.fileattr.acts.value;
1.35 matthew 265: }
266:
1.7 harris41 267: function changeURL(val) {
1.35 matthew 268: if (window.opener.document) {
269: window.opener.document.forms["$form"].elements["$element"].value=val;
270: } else {
271: alert("The file you selected is: "+val);
1.7 harris41 272: }
273: }
274: END
1.79 albertel 275: if (!$titleelement) {
276: $catalogmodefunctions.='function changeTitle(val) {}';
277: } else {
278: $catalogmodefunctions.=<<END;
279: function changeTitle(val) {
280: if (window.opener.document) {
281: window.opener.document.forms["$form"].elements["$titleelement"].value=val;
282: } else {
283: alert("The title of the file you selected is: "+val);
284: }
285: }
286: END
287: }
1.39 matthew 288: } elsif ($mode eq 'parmset') {
1.40 matthew 289: my $location = "/adm/groupsort?catalogmode=interactive&";
290: $location .= "form=$form&element=$element&mode=parmset&acts=";
1.39 matthew 291: $catalogmodefunctions=<<END;
292: // mode = $mode
1.108 albertel 293: function select_data(url) {
1.39 matthew 294: changeURL(url);
295: self.close();
296: }
297:
298: function select_group() {
1.40 matthew 299: window.location="$location"+document.forms.fileattr.acts.value;
1.39 matthew 300: }
301:
302: function changeURL(val) {
303: if (window.opener.document) {
304: var elementname = "$element"+"_value";
305: var checkboxname = "$element"+"_setparmval";
306: window.opener.document.forms["$form"].elements[elementname].value=val;
307: window.opener.document.forms["$form"].elements[checkboxname].checked=true;
308: } else {
309: alert("The file you selected is: "+val);
310: }
311: }
312:
313: END
314: }
1.15 harris41 315: }
1.38 matthew 316: $catalogmodefunctions.=<<END;
317: var acts='';
318: function rep_dirpath(suffix,val) {
319: eval("document.forms.dirpath"+suffix+".acts.value=val");
320: }
321: END
1.16 harris41 322: if ($ENV{'form.catalogmode'} eq 'groupimport') {
1.38 matthew 323: $catalogmodefunctions.=<<END;
1.16 harris41 324: function queue(val) {
325: if (eval("document.forms."+val+".filelink.checked")) {
326: var l=val.length;
327: var v=val.substring(4,l);
328: document.forms.fileattr.acts.value+='1a'+v+'b';
329: }
330: else {
331: var l=val.length;
332: var v=val.substring(4,l);
333: document.forms.fileattr.acts.value+='0a'+v+'b';
334: }
335: }
336: END
337: }
1.17 harris41 338:
1.1 www 339: # ---------------------------------------------------------------- Print Header
1.15 harris41 340: $r->print(<<ENDHEADER);
1.1 www 341: <html>
342: <head>
1.2 harris41 343: <title>The LearningOnline Network With CAPA Directory Browser</title>
1.3 harris41 344:
1.19 harris41 345: <script type="text/javascript">
1.7 harris41 346: $catalogmodefunctions
1.69 www 347: function openWindow(url, wdwName, w, h, toolbar,scrollbar,locationbar) {
1.71 ng 348: var xpos = (screen.width-w)/2;
349: xpos = (xpos < 0) ? '0' : xpos;
350: var ypos = (screen.height-h)/2-30;
351: ypos = (ypos < 0) ? '0' : ypos;
352: var options = "width=" + w + ",height=" + h + ",screenx="+xpos+",screeny="+ypos+",";
1.2 harris41 353: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
1.69 www 354: options += "menubar=no,toolbar="+toolbar+",location="+locationbar+",directories=no";
1.2 harris41 355: var newWin = window.open(url, wdwName, options);
356: newWin.focus();
357: }
1.16 harris41 358: function gothere(val) {
359: window.location=val+'?acts='+document.forms.fileattr.acts.value;
360: }
1.14 harris41 361: </script>
1.3 harris41 362:
1.1 www 363: </head>
364: ENDHEADER
1.74 www 365: my ($headerdom)=($uri=~/^\/res\/(\w+)\//);
366: $r->print(&Apache::loncommon::bodytag('Browse Resources',undef,undef,undef,
367: $headerdom));
1.17 harris41 368: # - Evaluate actions from previous page (both cumulatively and chronologically)
1.16 harris41 369: if ($ENV{'form.catalogmode'} eq 'groupimport') {
370: my $acts=$ENV{'form.acts'};
371: my @Acts=split(/b/,$acts);
372: my %ahash;
373: my %achash;
374: my $ac=0;
1.17 harris41 375: # some initial hashes for working with data
1.27 harris41 376: foreach (@Acts) {
1.16 harris41 377: my ($state,$ref)=split(/a/);
378: $ahash{$ref}=$state;
379: $achash{$ref}=$ac;
380: $ac++;
1.27 harris41 381: }
1.87 www 382: # sorting through the actions and changing the global database hash
1.27 harris41 383: foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
1.16 harris41 384: my $key=$_;
385: if ($ahash{$key} eq '1') {
386: $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
387: $hash{'pre_'.$key.'_title'};
388: $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
389: $hash{'storectr'}+0;
390: $hash{'storectr'}++;
391: }
392: if ($ahash{$key} eq '0') {
393: if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
394: delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
395: }
396: }
1.27 harris41 397: }
1.17 harris41 398: # deleting the previously cached listing
1.27 harris41 399: foreach (keys %hash) {
1.16 harris41 400: if ($_ =~ /^pre_/ && $_ =~/link$/) {
401: my $key = $_;
402: $key =~ s/^pre_//;
403: $key =~ s/_[^_]*$//;
404: delete $hash{'pre_'.$key.'_title'};
405: delete $hash{'pre_'.$key.'_link'};
406: }
1.27 harris41 407: }
1.16 harris41 408: }
409:
1.23 harris41 410: # ---------------------------------- get state of file attributes to be showing
1.87 www 411: if ($ENV{'form.attrs'}) {
1.111 ! www 412: for (my $i=0; $i<=11; $i++) {
1.6 harris41 413: delete $hash{'display_attrs_'.$i};
414: if ($ENV{'form.attr'.$i} == 1) {
1.45 ng 415: $attrchk[$i] = 'checked';
1.6 harris41 416: $hash{'display_attrs_'.$i} = 1;
417: }
418: }
419: } else {
1.111 ! www 420: for (my $i=0; $i<=11; $i++) {
1.45 ng 421: $attrchk[$i] = 'checked' if $hash{'display_attrs_'.$i} == 1;
1.6 harris41 422: }
423: }
1.87 www 424:
1.23 harris41 425: # ------------------------------- output state of file attributes to be showing
1.71 ng 426: # All versions has to the last item
427: # since it does not take an extra col
1.77 www 428: my %lt=&Apache::lonlocal::texthash(
429: 'ti' => 'Title',
430: 'si' => 'Size',
431: 'la' => 'Last access',
432: 'lm' => 'Last modified',
433: 'st' => 'Statistics',
434: 'au' => 'Author',
435: 'kw' => 'Keywords',
1.78 www 436: 'ln' => 'Language',
1.109 taceyjo1 437: 'sa' => 'Source Available',
1.77 www 438: 'sr' => 'Show resource',
1.111 ! www 439: 'li' => 'Linked/Related Resources',
1.77 www 440: 'av' => 'All versions',
441: 'ud' => 'Update Display'
442: );
1.81 sakharuk 443: my $Displayfileattributes=&mt('Display file attributes');
1.15 harris41 444: $r->print(<<END);
1.17 harris41 445: <form method="post" name="fileattr" action="$uri"
446: enctype="application/x-www-form-urlencoded">
1.81 sakharuk 447: <b><font color="#666666">$Displayfileattributes</font></b><br />
1.1 www 448: <table border=0><tr>
1.87 www 449: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] onClick="this.form.submit();" /> $lt{'ti'}</td>
450: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] onClick="this.form.submit();" /> $lt{'si'}</td>
451: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] onClick="this.form.submit();" /> $lt{'la'}</td>
452: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] onClick="this.form.submit();" /> $lt{'lm'}</td>
453: <td><input type="checkbox" name="attr8" value="1" $attrchk[8] onClick="this.form.submit();" /> $lt{'st'}</td>
1.109 taceyjo1 454: <td><input type="checkbox" name="attr10" value="1" $attrchk[10] onClick="this.form.submit();" /> $lt{'sa'}</td>
1.77 www 455: </tr><tr>
1.87 www 456: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] onClick="this.form.submit();" /> $lt{'au'}</td>
457: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] onClick="this.form.submit();" /> $lt{'kw'}</td>
458: <td><input type="checkbox" name="attr6" value="1" $attrchk[6] onClick="this.form.submit();" /> $lt{'ln'}</td>
459: <td><input type="checkbox" name="attr7" value="1" $attrchk[7] onClick="this.form.submit();" /> $lt{'sr'}</td>
460: <td><input type="checkbox" name="attr9" value="1" $attrchk[9] onClick="this.form.submit();" /> $lt{'av'}</td>
1.111 ! www 461: <td><input type="checkbox" name="attr11" value="1" $attrchk[11] onClick="this.form.submit();" /> $lt{'li'}</td>
1.1 www 462: </tr></table>
1.87 www 463: <input type="hidden" name="attrs" value="1" />
464: <input type="submit" name="updatedisplay" value="$lt{'ud'}" />
1.16 harris41 465: <input type="hidden" name="acts" value="" />
1.87 www 466: $closebutton $groupimportbutton
1.1 www 467: END
1.97 www 468: # -------------- Filter out sequence containment in crumbs and "recent folders"
469: my $storeuri=$uri;
470: $storeuri='/'.(split(/\.(page|sequence)\/\//,$uri))[-1];
471: $storeuri=~s/\/+/\//g;
1.82 www 472: # ---------------------------------------------------------------- Bread crumbs
1.97 www 473: $r->print(&Apache::lonhtmlcommon::crumbs($storeuri,'','',
1.87 www 474: (($ENV{'form.catalogmode'} eq 'groupimport')?
475: 'document.forms.fileattr':'')).
476: &Apache::lonhtmlcommon::select_recent('residx','resrecent',
1.100 www 477: 'this.form.action=this.form.resrecent.options[this.form.resrecent.selectedIndex].value;this.form.submit();'));
478: # -------------------------------------------------------- Resource Home Button
479: my $reshome=$ENV{'course.'.$ENV{'request.course.id'}.'.reshome'};
480: if ($reshome) {
481: $r->print("<font size='+2'><a href='");
482: if ($ENV{'form.catalogmode'} eq 'groupimport') {
483: $r->print('javascript:document.forms.fileattr.action="'.$reshome.'";document.forms.fileattr.submit();');
484: } else {
485: $r->print($reshome);
486: }
487: $r->print("'>".&mt('Home').'</a></font>');
488: }
489: $r->print('</form>');
1.85 www 490: # ------------------------------------------------------ Remember where we were
1.97 www 491: &Apache::loncommon::storeresurl($storeuri);
492: &Apache::lonhtmlcommon::store_recent('residx',$storeuri,$storeuri);
1.23 harris41 493: # ----------------- output starting row to the indexed file/directory hierarchy
1.15 harris41 494: my $titleclr="#ddffff";
1.40 matthew 495: # $r->print(&initdebug());
496: # $r->print(&writedebug("Omit:@Omit")) if (@Omit);
497: # $r->print(&writedebug("Only:@Only")) if (@Only);
1.46 ng 498: $r->print("<table width='100\%' border=0><tr><td bgcolor=#777777>\n");
1.45 ng 499: $r->print("<table width='100\%' border=0><tr bgcolor=$titleclr>\n");
1.77 www 500: $r->print("<td $colspan><b>".&mt('Name')."</b></td>\n");
501: $r->print("<td><b>".&mt('Title')."</b></td>\n")
1.45 ng 502: if ($hash{'display_attrs_0'} == 1);
1.77 www 503: $r->print("<td align=right><b>".&mt("Size")." (".&mt("bytes").") ".
1.45 ng 504: "</b></td>\n") if ($hash{'display_attrs_1'} == 1);
1.77 www 505: $r->print("<td><b>".&mt("Last accessed")."</b></td>\n")
1.17 harris41 506: if ($hash{'display_attrs_2'} == 1);
1.77 www 507: $r->print("<td><b>".&mt("Last modified")."</b></td>\n")
1.17 harris41 508: if ($hash{'display_attrs_3'} == 1);
1.77 www 509: $r->print("<td><b>".&mt("Author(s)")."</b></td>\n")
1.17 harris41 510: if ($hash{'display_attrs_4'} == 1);
1.77 www 511: $r->print("<td><b>".&mt("Keywords")."</b></td>\n")
1.17 harris41 512: if ($hash{'display_attrs_5'} == 1);
1.77 www 513: $r->print("<td><b>".&mt("Language")."</b></td>\n")
1.45 ng 514: if ($hash{'display_attrs_6'} == 1);
1.77 www 515: $r->print("<td><b>".&mt("Resource")."</b></td>\n")
1.63 ng 516: if ($hash{'display_attrs_7'} == 1);
1.77 www 517: $r->print("<td><b>".&mt("Usage Statistics")." <br />(".
518: &mt("Courses/Network Hits").")</b></td>\n")
1.70 ng 519: if ($hash{'display_attrs_8'} == 1);
1.109 taceyjo1 520: $r->print("<td><b>".&mt("Source Available")."</b></td>\n")
521: if ($hash{'display_attrs_10'} == 1);
1.111 ! www 522: $r->print("<td><b>".&mt("Linked/Related Resources")."</b></td>\n")
! 523: if ($hash{'display_attrs_11'} == 1);
1.45 ng 524: $r->print('</tr>');
1.5 harris41 525:
1.23 harris41 526: # ----------------- read in what directories have previously been set to "open"
1.27 harris41 527: foreach (keys %hash) {
1.4 harris41 528: if ($_ =~ /^diropen_status_/) {
529: my $key = $_;
530: $key =~ s/^diropen_status_//;
531: $dirs{$key} = $hash{$_};
532: }
1.27 harris41 533: }
1.4 harris41 534:
1.2 harris41 535: if ($ENV{'form.openuri'}) { # take care of review and refresh options
536: my $uri=$ENV{'form.openuri'};
1.4 harris41 537: if (exists($hash{'diropen_status_'.$uri})) {
538: my $cursta = $hash{'diropen_status_'.$uri};
1.2 harris41 539: $dirs{$uri} = 'open';
1.4 harris41 540: $hash{'diropen_status_'.$uri} = 'open';
541: if ($cursta eq 'open') {
542: $dirs{$uri} = 'closed';
543: $hash{'diropen_status_'.$uri} = 'closed';
544: }
1.2 harris41 545: } else {
1.4 harris41 546: $hash{'diropen_status_'.$uri} = 'open';
1.2 harris41 547: $dirs{$uri} = 'open';
548: }
549: }
1.12 ng 550:
551: my $toplevel;
1.13 ng 552: my $indent = 0;
1.12 ng 553: $uri = $uri.'/' if $uri !~ /.*\/$/;
1.17 harris41 554:
1.88 www 555: if ($ENV{'form.dirPointer'} ne 'on') {
556: $hash{'top.level'} = $uri;
557: $toplevel = $uri;
558: } else {
559: $toplevel = $hash{'top.level'};
560: }
1.17 harris41 561:
1.23 harris41 562: # -------------------------------- if not at top level, provide an uplink arrow
1.45 ng 563: if ($toplevel ne '/res/'){
1.13 ng 564: my (@uri_com) = split(/\//,$uri);
565: pop @uri_com;
566: my $upone = join('/',@uri_com);
567: my @list = qw (0);
568: &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
569: $indent = 1;
1.12 ng 570: }
1.17 harris41 571:
1.23 harris41 572: # -------- recursively go through all the directories and output as appropriate
1.16 harris41 573: &scanDir ($r,$toplevel,$indent,\%hash);
1.12 ng 574:
1.23 harris41 575: # ---------------------------- embed hidden information useful for group import
1.8 harris41 576: $r->print("<form name='fnum'>");
577: $r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
1.17 harris41 578:
1.23 harris41 579: # -------------------------------------------------------------- end the tables
1.45 ng 580: $r->print('</table>');
581: $r->print('</td></tr></table>');
1.17 harris41 582:
1.23 harris41 583: # --------------------------------------------------- end the output and return
1.45 ng 584: $r->print('</body></html>'."\n");
1.2 harris41 585: }
1.67 matthew 586: if(! $c->aborted()) {
1.87 www 587: # write back into the temporary file
1.68 albertel 588: my %dbfile;
1.67 matthew 589: if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_NEWDB(),0640)) {
590: while (my($key,$value) = each(%hash)) {
591: $dbfile{$key}=$value;
592: }
593: untie(%dbfile);
594: }
595: }
596:
1.1 www 597: return OK;
598: }
1.2 harris41 599:
1.17 harris41 600: # ----------------------------------------------- recursive scan of a directory
1.2 harris41 601: sub scanDir {
1.16 harris41 602: my ($r,$startdir,$indent,$hashref)=@_;
1.67 matthew 603: my $c = $r->connection();
1.3 harris41 604: my ($compuri,$curdir);
605: my $dirptr=16384;
1.90 taceyjo1 606: my $obs;
1.1 www 607: $indent++;
1.2 harris41 608: my %dupdirs = %dirs;
609: my @list=&get_list($r,$startdir);
610: foreach my $line (@list) {
1.67 matthew 611: return if ($c->aborted());
1.90 taceyjo1 612: #This is a kludge, sorry aboot this
1.92 taceyjo1 613: my ($strip,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1.90 taceyjo1 614: next if($strip =~ /.*\.meta$/ | $obs eq '1');
1.18 ng 615: my (@fileparts) = split(/\./,$strip);
1.70 ng 616: if ($hash{'display_attrs_9'} != 1) {
1.95 www 617: # if not all versions to be shown
1.18 ng 618: if (scalar(@fileparts) >= 3) {
619: my $fext = pop @fileparts;
620: my $ov = pop @fileparts;
621: my $fname = join ('.',@fileparts,$fext);
1.75 albertel 622: next if (grep /\Q$fname\E/,@list and $ov =~ /^\d+$/);
1.18 ng 623: }
624: }
625:
1.45 ng 626: if ($dom eq 'domain') {
1.72 albertel 627: # dom list has full path /res/<domain name>/ already
628: $curdir='';
1.73 albertel 629: $compuri = (split(/\&/,$line))[0];
1.2 harris41 630: } else {
1.17 harris41 631: # user, dir & file have name only, i.e., w/o path
1.45 ng 632: $compuri = join('',$startdir,$strip,'/');
1.3 harris41 633: $curdir = $startdir;
1.2 harris41 634: }
1.45 ng 635: my $diropen = 'closed';
1.96 www 636: if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/) or ($compuri=~/\.(sequence|page)\/$/)) {
1.3 harris41 637: while (my ($key,$val)= each %dupdirs) {
1.5 harris41 638: if ($key eq $compuri and $val eq "open") {
1.11 ng 639: $diropen = "opened";
1.53 albertel 640: delete($dupdirs{$key});
641: delete($dirs{$key});
1.5 harris41 642: }
1.3 harris41 643: }
1.1 www 644: }
1.16 harris41 645: &display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
1.45 ng 646: &scanDir ($r,$compuri,$indent) if $diropen eq 'opened';
1.1 www 647: }
648: $indent--;
649: }
650:
1.17 harris41 651: # --------------- get complete matched list based on the uri (returns an array)
1.1 www 652: sub get_list {
653: my ($r,$uri)=@_;
1.97 www 654: my @list=();
1.45 ng 655: (my $luri = $uri) =~ s/\//_/g;
1.87 www 656: if ($ENV{'form.updatedisplay'}) {
1.27 harris41 657: foreach (keys %hash) {
1.4 harris41 658: delete $hash{$_} if ($_ =~ /^dirlist_files_/);
1.87 www 659: }
1.2 harris41 660: }
661:
1.87 www 662: if ($hash{'dirlist_files_'.$luri}) {
1.4 harris41 663: @list = split(/\n/,$hash{'dirlist_files_'.$luri});
1.97 www 664: } elsif ($uri=~/\.(page|sequence)\/$/) {
1.94 www 665: # is a page or a sequence
1.97 www 666: $uri=~s/\/$//;
667: $uri='/'.(split(/\.(page|sequence)\/\//,$uri))[-1];
668: $uri=~s/\/+/\//g;
669: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$uri))) {
670: my @ratpart=split(/\:/,$_);
671: push @list,$ratpart[1];
672: }
1.94 www 673: $hash{'dirlist_files_'.$luri} = join("\n",@list);
1.1 www 674: } else {
1.94 www 675: # is really a directory
1.4 harris41 676: @list = &Apache::lonnet::dirlist($uri);
1.87 www 677: $hash{'dirlist_files_'.$luri} = join("\n",@list);
1.1 www 678: }
1.91 taceyjo1 679: return @list=&match_ext($r,@list);
1.1 www 680: }
681:
1.40 matthew 682: sub initdebug {
683: return <<ENDJS;
684: <script>
685: var debugging = true;
686: if (debugging) {
687: var debuggingWindow = window.open('','Debug','width=400,height=300',true);
688: }
689:
690: function output(text) {
691: if (debugging) {
692: debuggingWindow.document.writeln(text);
693: }
694: }
695: output("<html><head><title>Debugging Window</title></head><body><pre>");
696: </script>
697: ENDJS
698: }
699:
700: sub writedebug {
701: my $text = shift;
702: return "<script>output('$text');</script>";
703: }
704:
1.17 harris41 705: # -------------------- filters out files based on extensions (returns an array)
1.1 www 706: sub match_ext {
707: my ($r,@packlist)=@_;
708: my @trimlist;
709: my $nextline;
710: my @fileext;
711: my $dirptr=16384;
712:
1.2 harris41 713: foreach my $line (@packlist) {
714: chomp $line;
715: $line =~ s/^\/home\/httpd\/html//;
716: my @unpackline = split (/\&/,$line);
1.45 ng 717: next if ($unpackline[0] eq '.');
718: next if ($unpackline[0] eq '..');
1.2 harris41 719: my @filecom = split (/\./,$unpackline[0]);
720: my $fext = pop(@filecom);
1.96 www 721: my $fnptr = ($unpackline[3]&$dirptr) || ($fext=~/\.(page|sequence)$/);
1.2 harris41 722: if ($fnptr == 0 and $unpackline[3] ne "") {
1.28 harris41 723: my $embstyle = &Apache::loncommon::fileembstyle($fext);
1.25 matthew 724: push @trimlist,$line if (defined($embstyle) &&
1.32 harris41 725: ($embstyle ne 'hdn' or $fext eq 'meta'));
1.1 www 726: } else {
1.2 harris41 727: push @trimlist,$line;
1.1 www 728: }
729: }
1.80 albertel 730: @trimlist = sort {uc($a) cmp uc($b)} (@trimlist);
1.1 www 731: return @trimlist;
732: }
733:
1.17 harris41 734: # ------------------------------- displays one line in appropriate table format
1.23 harris41 735: sub display_line {
1.16 harris41 736: my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
1.53 albertel 737: my (@pathfn, $fndir);
1.97 www 738: # there could be relative paths (files actually belonging into this directory)
739: # or absolute paths (for example, from sequences)
740: my $absolute;
741: my $pathprefix;
1.107 albertel 742: if ($line=~m|^/res/| && $startdir ne '') {
1.97 www 743: $absolute=1;
744: $pathprefix='';
745: } else {
746: $absolute=0;
747: $pathprefix=$startdir;
748: }
1.1 www 749: my $dirptr=16384;
750: my $fileclr="#ffffe6";
1.45 ng 751: my $iconpath= $r->dir_config('lonIconsURL') . '/';
1.1 www 752:
753: my @filecom = split (/\&/,$line);
754: my @pathcom = split (/\//,$filecom[0]);
755: my $listname = $pathcom[scalar(@pathcom)-1];
756: my $fnptr = $filecom[3]&$dirptr;
1.77 www 757: my $msg = &mt('View').' '.$filecom[0].' '.&mt('resources');
758: $msg = &mt('Close').' '.$filecom[0].' '.&mt('directory') if $diropen eq 'opened';
1.1 www 759:
1.45 ng 760: my $tabtag='</td>';
1.1 www 761: my $i=0;
1.109 taceyjo1 762: while ($i<=11) {
1.45 ng 763: $tabtag=join('',$tabtag,"<td> </td>")
1.17 harris41 764: if $hash{'display_attrs_'.$i} == 1;
1.1 www 765: $i++;
766: }
1.63 ng 767: my $valign = ($hash{'display_attrs_7'} == 1 ? 'top' : 'bottom');
1.17 harris41 768:
769: # display uplink arrow
1.45 ng 770: if ($filecom[1] eq 'viewOneUp') {
1.98 www 771: my $updir=$startdir;
772: # -------------- Filter out sequence containment in crumbs and "recent folders"
773: $updir='/'.(split(/\.(page|sequence)\/\//,$startdir))[-1];
774: $updir=~s/\/+/\//g;
775:
1.70 ng 776: $r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
777: $r->print("<td>\n");
1.98 www 778: $r->print ('<form method="post" name="dirpathUP" action="'.$updir.
1.16 harris41 779: '/" '.
1.17 harris41 780: 'onSubmit="return rep_dirpath(\'UP\','.
781: 'document.forms.fileattr.acts.value)" '.
1.16 harris41 782: 'enctype="application/x-www-form-urlencoded"'.
783: '>'."\n");
1.17 harris41 784: $r->print ('<input type=hidden name=openuri value="'.
785: $startdir.'">'."\n");
1.16 harris41 786: $r->print ('<input type="hidden" name="acts" value="">'."\n");
1.13 ng 787: $r->print ('<input src="'.$iconpath.'arrow_up.gif"');
1.17 harris41 788: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
789: "\n");
1.77 www 790: $r->print(&mt("Up")." $tabtag</tr></form>\n");
1.13 ng 791: return OK;
792: }
1.97 www 793: # Do we have permission to look at this?
794:
795: if($filecom[15] ne '1') { return OK if (!&Apache::lonnet::allowed('bre',$pathprefix.$filecom[0])); }
796:
797: # make absolute links appear on different background
798: if ($absolute) { $fileclr='#aaaa88'; }
1.17 harris41 799:
800: # display domain
1.45 ng 801: if ($filecom[1] eq 'domain') {
1.88 www 802: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
803: if ($ENV{'form.dirPointer'} eq "on");
1.70 ng 804: $r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
805: $r->print("<td>");
1.73 albertel 806: &begin_form ($r,$filecom[0]);
807: my $anchor = $filecom[0];
1.3 harris41 808: $anchor =~ s/\///g;
1.13 ng 809: $r->print ('<a name="'.$anchor.'">');
1.16 harris41 810: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 811: $r->print ('<input src="'.$iconpath.'folder_pointer_'.
812: $diropen.'.gif"');
813: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
814: "\n");
815: $r->print ('<a href="javascript:gothere(\''.$filecom[0].
1.73 albertel 816: '\')"><img src="'.$iconpath.'server.gif"');
1.17 harris41 817: $r->print (' border="0" /></a>'."\n");
1.77 www 818: $r->print (&mt("Domain")." - $listname ");
1.60 albertel 819: if ($Apache::lonnet::domaindescription{$listname}) {
820: $r->print("(".$Apache::lonnet::domaindescription{$listname}.
821: ")");
822: }
823: $r->print (" $tabtag</tr></form>\n");
1.1 www 824: return OK;
1.17 harris41 825:
826: # display user directory
1.1 www 827: }
1.45 ng 828: if ($filecom[1] eq 'user') {
1.70 ng 829: $r->print("<tr valign=$valign bgcolor=$fileclr>$extrafield");
830: $r->print("<td nowrap>\n");
1.2 harris41 831: my $curdir = $startdir.$filecom[0].'/';
1.3 harris41 832: my $anchor = $curdir;
833: $anchor =~ s/\///g;
1.13 ng 834: &begin_form ($r,$curdir);
1.17 harris41 835: $r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
836: 'whitespace1.gif" border="0" />'."\n");
1.16 harris41 837: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 838: $r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
839: '.gif"');
840: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
841: "\n");
842: $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
843: $iconpath.'quill.gif border="0" name="'.$msg.
844: '" height="22" /></a>');
1.60 albertel 845: my $domain=(split(m|/|,$startdir))[2];
846: my $plainname=&Apache::loncommon::plainname($listname,$domain);
847: $r->print ($listname);
848: if (defined($plainname) && $plainname) { $r->print(" ($plainname) "); }
849: $r->print ($tabtag.'</tr></form>'."\n");
1.1 www 850: return OK;
851: }
1.17 harris41 852:
1.1 www 853: # display file
1.97 www 854: if (($fnptr == 0 and $filecom[3] ne '') or $absolute) {
855: my $filelink = $pathprefix.$filecom[0];
1.1 www 856: my @file_ext = split (/\./,$listname);
1.25 matthew 857: my $curfext = $file_ext[-1];
1.40 matthew 858: if (@Omit) {
859: foreach (@Omit) { return OK if ($curfext eq $_); }
860: }
861: if (@Only) {
862: my $skip = 1;
863: foreach (@Only) { $skip = 0 if ($curfext eq $_); }
864: return OK if ($skip > 0);
865: }
1.25 matthew 866: # Set the icon for the file
1.84 albertel 867: my $iconname = &Apache::loncommon::icon($listname);
1.70 ng 868: $r->print("<tr valign='$valign' bgcolor=$fileclr><td nowrap>");
1.104 albertel 869:
870: my $metafile = $Apache::lonnet::perlvar{'lonDocRoot'}.$pathprefix.
871: $filecom[0].'.meta';
872: if (-e $metafile) {
873: $metafile=1;
874: } else {
875: $metafile=0;
876: }
1.7 harris41 877: if ($ENV{'form.catalogmode'} eq 'interactive') {
1.35 matthew 878: $r->print("<a href=\"javascript:select_data(\'",
1.108 albertel 879: $filelink,"')\">");
1.17 harris41 880: $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
881: "\n");
1.70 ng 882: $r->print("</td><td nowrap>");
1.95 www 883: } elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
1.8 harris41 884: $r->print("<form name='form$fnum'>\n");
885: $r->print("<input type='checkbox' name='filelink"."' ".
1.16 harris41 886: "value='$filelink' onClick='".
887: "javascript:queue(\"form$fnum\")' ");
888: if ($hash{'store_'.$filelink}) {
889: $r->print("checked");
890: }
891: $r->print(">\n");
1.8 harris41 892: $r->print("</form>\n");
1.70 ng 893: $r->print("</td><td nowrap>");
1.16 harris41 894: $hash{"pre_${fnum}_link"}=$filelink;
1.8 harris41 895: $fnum++;
1.7 harris41 896: }
1.95 www 897: # Form to open or close sequences
898: if ($filelink=~/\.(page|sequence)$/) {
899: my $curdir = $startdir.$filecom[0].'/';
900: my $anchor = $curdir;
901: $anchor =~ s/\///g;
902: &begin_form($r,$curdir);
903: $indent--;
904: }
905: # General indentation
1.12 ng 906: if ($indent > 0 and $indent < 11) {
1.17 harris41 907: $r->print("<img src=",$iconpath,"whitespace",$indent,
908: ".gif border='0' />\n");
1.11 ng 909: } elsif ($indent >0) {
1.4 harris41 910: my $ten = int($indent/10.);
911: my $rem = $indent%10.0;
912: my $count = 0;
913: while ($count < $ten) {
1.17 harris41 914: $r->print("<img src=",$iconpath,
915: "whitespace10.gif border='0' />\n");
1.1 www 916: $count++;
1.4 harris41 917: }
1.17 harris41 918: $r->print("<img src=",$iconpath,"whitespace",$rem,
919: ".gif border='0' />\n") if $rem > 0;
1.1 www 920: }
1.95 www 921: # Sequence open/close icon
922: if ($filelink=~/\.(page|sequence)$/) {
923: my $curdir = $startdir.$filecom[0].'/';
924: my $anchor = $curdir;
925: $anchor =~ s/\///g;
926: $r->print ('<input type="hidden" name="acts" value="">');
927: $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
928: 'folder_pointer_'.$diropen.'.gif"');
929: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
930: "\n");
931: }
932: # Filetype icons
1.84 albertel 933: $r->print("<img src='$iconname' border='0' />\n");
1.95 www 934: # Close form to open/close sequence
935: if ($filelink=~/\.(page|sequence)$/) {
936: $r->print('</form>');
937: }
1.17 harris41 938: $r->print (" <a href=\"javascript:openWindow('".$filelink.
1.69 www 939: "', 'previewfile', '450', '500', 'no', 'yes','yes')\";".
1.17 harris41 940: " TARGET=_self>$listname</a> ");
941:
942: $r->print (" (<a href=\"javascript:openWindow('".$filelink.
1.71 ng 943: ".meta', 'metadatafile', '500', '550', 'no', 'yes','no')\"; ".
1.104 albertel 944: "TARGET=_self>metadata</a>) ");
1.7 harris41 945: $r->print("</td>\n");
1.45 ng 946: if ($hash{'display_attrs_0'} == 1) {
1.104 albertel 947: my $title = &Apache::lonnet::gettitle($filelink,'title');
1.70 ng 948: $r->print('<td> '.($title eq '' ? ' ' : $title).
1.45 ng 949: ' </td>'."\n");
950: }
1.70 ng 951: $r->print('<td align=right> ',
1.17 harris41 952: $filecom[8]," </td>\n")
1.45 ng 953: if $hash{'display_attrs_1'} == 1;
1.70 ng 954: $r->print('<td> '.
1.17 harris41 955: (localtime($filecom[9]))." </td>\n")
1.45 ng 956: if $hash{'display_attrs_2'} == 1;
1.70 ng 957: $r->print('<td> '.
1.17 harris41 958: (localtime($filecom[10]))." </td>\n")
1.45 ng 959: if $hash{'display_attrs_3'} == 1;
1.2 harris41 960:
1.45 ng 961: if ($hash{'display_attrs_4'} == 1) {
1.104 albertel 962: my $author = &Apache::lonnet::metadata($filelink,'author');
1.70 ng 963: $r->print('<td> '.($author eq '' ? ' ' : $author).
1.17 harris41 964: " </td>\n");
1.2 harris41 965: }
1.45 ng 966: if ($hash{'display_attrs_5'} == 1) {
1.104 albertel 967: my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
1.45 ng 968: # $keywords = ' ' if (!$keywords);
1.70 ng 969: $r->print('<td> '.($keywords eq '' ? ' ' : $keywords).
1.17 harris41 970: " </td>\n");
1.2 harris41 971: }
1.109 taceyjo1 972: #'
973:
1.45 ng 974: if ($hash{'display_attrs_6'} == 1) {
1.104 albertel 975: my $lang = &Apache::lonnet::metadata($filelink,'language');
1.28 harris41 976: $lang = &Apache::loncommon::languagedescription($lang);
1.70 ng 977: $r->print('<td> '.($lang eq '' ? ' ' : $lang).
1.17 harris41 978: " </td>\n");
1.2 harris41 979: }
1.63 ng 980: if ($hash{'display_attrs_7'} == 1) {
1.56 www 981: my $output='';
1.57 www 982: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
983: if ($embstyle eq 'ssi') {
1.89 www 984: my $cache=$Apache::lonnet::perlvar{'lonDocRoot'}.$filelink.
985: '.tmp';
986: if ((!$ENV{'form.updatedisplay'}) &&
987: (-e $cache)) {
988: open(FH,$cache);
989: $output=join("\n",<FH>);
990: close(FH);
991: } else {
992: $output=&Apache::lonnet::ssi_body($filelink);
993: open(FH,">$cache");
994: print FH $output;
995: close(FH);
996: }
997: $output='<font size="-2">'.$output.'</font>';
1.57 www 998: } elsif ($embstyle eq 'img') {
999: $output='<img src="'.$filelink.'" />';
1.58 www 1000: } elsif ($filelink=~/^\/res\/(\w+)\/(\w+)\//) {
1001: $output='<img src="http://'.
1002: $Apache::lonnet::hostname{&Apache::lonnet::homeserver($2,$1)}.
1003: '/cgi-bin/thumbnail.gif?url='.$filelink.'" />';
1.57 www 1004: }
1.70 ng 1005: $r->print('<td> '.($output eq '' ? ' ':$output).
1.56 www 1006: " </td>\n");
1007: }
1.70 ng 1008: if ($hash{'display_attrs_8'} == 1) {
1.111 ! www 1009: # statistics
! 1010: $r->print("<td> </td>\n");
! 1011:
1.70 ng 1012: }
1.109 taceyjo1 1013: if ($hash{'display_attrs_10'} == 1) {
1014: my $source = &Apache::lonnet::metadata($filelink,'sourceavail');
1.110 albertel 1015: if($source eq 'open') {
1016: my $sourcelink = &Apache::lonsource::make_link($filelink);
1017: $r->print('<td>'."<a href=\"javascript:openWindow('".$sourcelink.
1018: "', 'previewsource', '700', '700', 'no', 'yes','yes')\";".
1019: " TARGET=_self>Yes</a> "."</td>\n");
1020: } else { #A cuddled else. :P
1.111 ! www 1021: $r->print("<td> </td>\n");
1.110 albertel 1022: }
1.109 taceyjo1 1023: }
1.111 ! www 1024: if ($hash{'display_attrs_11'} == 1) {
! 1025: # links
! 1026: $r->print("<td> </td>\n");
! 1027: }
1.1 www 1028: $r->print("</tr>\n");
1029: }
1.17 harris41 1030:
1.2 harris41 1031: # -- display directory
1.1 www 1032: if ($fnptr == $dirptr) {
1.2 harris41 1033: my $curdir = $startdir.$filecom[0].'/';
1.3 harris41 1034: my $anchor = $curdir;
1035: $anchor =~ s/\///g;
1.63 ng 1036: $r->print("<tr bgcolor=$fileclr>$extrafield<td valign=$valign>");
1.2 harris41 1037: &begin_form ($r,$curdir);
1.4 harris41 1038: my $indentm1 = $indent-1;
1.11 ng 1039: if ($indentm1 < 11 and $indentm1 > 0) {
1.17 harris41 1040: $r->print("<img src=",$iconpath,"whitespace",$indentm1,
1041: ".gif border='0' />\n");
1.4 harris41 1042: } else {
1043: my $ten = int($indentm1/10.);
1044: my $rem = $indentm1%10.0;
1045: my $count = 0;
1046: while ($count < $ten) {
1.17 harris41 1047: $r->print ("<img src=",$iconpath
1048: ,"whitespace10.gif border='0' />\n");
1.12 ng 1049: $count++;
1.4 harris41 1050: }
1.17 harris41 1051: $r->print ("<img src=",$iconpath,"whitespace",$rem,
1052: ".gif border='0' />\n") if $rem > 0;
1.1 www 1053: }
1.16 harris41 1054: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 1055: $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
1056: 'folder_pointer_'.$diropen.'.gif"');
1057: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
1058: "\n");
1059: $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
1060: $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
1061: "\n");
1.86 www 1062: $r->print ("$listname</td>\n");
1063: # Attributes
1064: my $filelink = $startdir.$filecom[0].'/default';
1065:
1066: if ($hash{'display_attrs_0'} == 1) {
1067: my $title = &Apache::lonnet::gettitle($filelink,'title');
1068: $r->print('<td> '.($title eq '' ? ' ' : $title).
1069: ' </td>'."\n");
1070: }
1071: $r->print('<td align=right> ',
1072: $filecom[8]," </td>\n")
1073: if $hash{'display_attrs_1'} == 1;
1074: $r->print('<td> '.
1075: (localtime($filecom[9]))." </td>\n")
1076: if $hash{'display_attrs_2'} == 1;
1077: $r->print('<td> '.
1078: (localtime($filecom[10]))." </td>\n")
1079: if $hash{'display_attrs_3'} == 1;
1080:
1081: if ($hash{'display_attrs_4'} == 1) {
1082: my $author = &Apache::lonnet::metadata($filelink,'author');
1083: $r->print('<td> '.($author eq '' ? ' ' : $author).
1084: " </td>\n");
1085: }
1086: if ($hash{'display_attrs_5'} == 1) {
1087: my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
1088: # $keywords = ' ' if (!$keywords);
1089: $r->print('<td> '.($keywords eq '' ? ' ' : $keywords).
1090: " </td>\n");
1091: }
1092: if ($hash{'display_attrs_6'} == 1) {
1093: my $lang = &Apache::lonnet::metadata($filelink,'language');
1094: $lang = &Apache::loncommon::languagedescription($lang);
1095: $r->print('<td> '.($lang eq '' ? ' ' : $lang).
1096: " </td>\n");
1097: }
1098: if ($hash{'display_attrs_7'} == 1) {
1099: $r->print('<td> </td>');
1100: }
1101: if ($hash{'display_attrs_8'} == 1) {
1102: $r->print('<td> </td>');
1103: }
1.109 taceyjo1 1104: if ($hash{'display_attrs_10'} == 1) {
1105: $r->print('<td> </td>');
1106: }
1.111 ! www 1107: if ($hash{'display_attrs_11'} == 1) {
! 1108: $r->print('<td> </td>');
! 1109: }
1.86 www 1110: $r->print('</form></tr>');
1.1 www 1111: }
1.2 harris41 1112:
1.1 www 1113: }
1114:
1.14 harris41 1115: # ------------------- prints the beginning of a form for directory or file link
1.1 www 1116: sub begin_form {
1117: my ($r,$uri) = @_;
1.3 harris41 1118: my $anchor = $uri;
1119: $anchor =~ s/\///g;
1.17 harris41 1120: $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
1121: '#'.$anchor.
1122: '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
1123: ',document.forms.fileattr.acts.value)" '.
1.16 harris41 1124: 'enctype="application/x-www-form-urlencoded">'."\n");
1.17 harris41 1125: $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
1126: "\n");
1.88 www 1127: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
1.16 harris41 1128: $dnum++;
1.17 harris41 1129: }
1130:
1131: # --------- settings whenever the user causes the indexer window to be launched
1132: sub start_fresh_session {
1.48 matthew 1133: delete $hash{'form.catalogmode'};
1134: delete $hash{'form.mode'};
1135: delete $hash{'form.form'};
1136: delete $hash{'form.element'};
1137: delete $hash{'form.omit'};
1138: delete $hash{'form.only'};
1.27 harris41 1139: foreach (keys %hash) {
1.48 matthew 1140: delete $hash{$_} if (/^(pre_|store)/);
1.27 harris41 1141: }
1.1 www 1142: }
1143:
1.35 matthew 1144: # ------------------------------------------------------------------- setvalues
1145: sub setvalues {
1146: # setvalues is used in registerurl to synchronize the database
1147: # hash and environment hashes
1148: my ($H1,$h1key,$H2,$h2key) =@_;
1149: #
1150: if (exists $H2->{$h2key}) {
1151: $H1->{$h1key} = $H2->{$h2key};
1152: } elsif (exists $H1->{$h1key}) {
1153: $H2->{$h2key} = $H1->{$h1key};
1154: }
1155: }
1156:
1.1 www 1157: 1;
1.54 www 1158:
1159: sub cleanup {
1.55 www 1160: if (tied(%hash)){
1161: &Apache::lonnet::logthis('Cleanup indexer: hash');
1162: }
1.54 www 1163: }
1.23 harris41 1164:
1165: =head1 NAME
1166:
1167: Apache::lonindexer - mod_perl module for cross server filesystem browsing
1168:
1169: =head1 SYNOPSIS
1170:
1171: Invoked by /etc/httpd/conf/srm.conf:
1172:
1173: <LocationMatch "^/res.*/$">
1174: SetHandler perl-script
1175: PerlHandler Apache::lonindexer
1176: </LocationMatch>
1177:
1178: =head1 INTRODUCTION
1179:
1180: This module enables a scheme of browsing across a cross server.
1181:
1182: This is part of the LearningOnline Network with CAPA project
1183: described at http://www.lon-capa.org.
1184:
1185: =head1 BEGIN SUBROUTINE
1186:
1187: This routine is only run once after compilation.
1188:
1189: =over 4
1190:
1191: =item *
1192:
1193: Initializes %language hash table.
1194:
1195: =back
1196:
1197: =head1 HANDLER SUBROUTINE
1198:
1199: This routine is called by Apache and mod_perl.
1200:
1201: =over 4
1202:
1203: =item *
1204:
1205: read in machine configuration variables
1206:
1207: =item *
1208:
1209: see if called from an interactive mode
1210:
1211: =item *
1212:
1213: refresh environment with user database values (in %hash)
1214:
1215: =item *
1216:
1217: define extra fields and buttons in case of special mode
1218:
1219: =item *
1220:
1221: set catalogmodefunctions to have extra needed javascript functionality
1222:
1223: =item *
1224:
1225: print header
1226:
1227: =item *
1228:
1229: evaluate actions from previous page (both cumulatively and chronologically)
1230:
1231: =item *
1232:
1233: output title
1234:
1235: =item *
1236:
1237: get state of file attributes to be showing
1238:
1239: =item *
1240:
1241: output state of file attributes to be showing
1242:
1243: =item *
1244:
1245: output starting row to the indexed file/directory hierarchy
1246:
1247: =item *
1248:
1249: read in what directories have previously been set to "open"
1250:
1251: =item *
1252:
1253: if not at top level, provide an uplink arrow
1254:
1255: =item *
1256:
1257: recursively go through all the directories and output as appropriate
1258:
1259: =item *
1260:
1261: information useful for group import
1262:
1263: =item *
1264:
1265: end the tables
1266:
1267: =item *
1268:
1269: end the output and return
1270:
1271: =back
1272:
1273: =head1 OTHER SUBROUTINES
1274:
1275: =over 4
1276:
1277: =item *
1278:
1279: scanDir - recursive scan of a directory
1280:
1281: =item *
1282:
1283: get_list - get complete matched list based on the uri (returns an array)
1284:
1285: =item *
1286:
1287: match_ext - filters out files based on extensions (returns an array)
1288:
1289: =item *
1290:
1291: display_line - displays one line in appropriate table format
1292:
1293: =item *
1294:
1295: begin_form - prints the beginning of a form for directory or file link
1296:
1297: =item *
1298:
1299: start_fresh_session - settings whenever the user causes the indexer window
1300: to be launched
1301:
1302: =back
1303:
1304: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>