Annotation of loncom/interface/lonindexer.pm, revision 1.113
1.1 www 1: # The LearningOnline Network with CAPA
1.24 harris41 2: # Directory Indexer
3: #
1.113 ! www 4: # $Id: lonindexer.pm,v 1.112 2004/06/17 01:44:34 www 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.2 harris41 56: use GDBM_File;
57:
1.23 harris41 58: # ---------------------------------------- variables used throughout the module
1.87 www 59: my %hash; # global user-specific gdbm file
1.17 harris41 60: my %dirs; # keys are directories, values are the open/close status
61: my %language; # has the reference information present in language.tab
1.111 www 62: my %dynhash; # hash of hashes for dynamic metadata
1.113 ! www 63: my %fieldnames; # Metadata fieldnames
1.17 harris41 64: # ----- Values which are set by the handler subroutine and are accessible to
65: # ----- other methods.
66: my $extrafield; # default extra table cell
67: my $fnum; # file counter
68: my $dnum; # directory counter
1.1 www 69:
1.40 matthew 70: # ----- Used to include or exclude files with certain extensions.
1.43 matthew 71: my @Only = ();
1.40 matthew 72: my @Omit = ();
73:
74:
1.23 harris41 75: # ----------------------------- Handling routine called via Apache and mod_perl
1.1 www 76: sub handler {
77: my $r = shift;
1.67 matthew 78: my $c = $r->connection();
1.76 www 79: &Apache::loncommon::content_type($r,'text/html');
1.50 albertel 80: &Apache::loncommon::no_cache($r);
1.1 www 81: $r->send_http_header;
82: return OK if $r->header_only;
1.9 harris41 83: $fnum=0;
1.16 harris41 84: $dnum=0;
1.17 harris41 85:
1.43 matthew 86: # Deal with stupid global variables (is there a way around making
87: # these global to this package? It is just so wrong....)
88: undef (@Only);
89: undef (@Omit);
1.113 ! www 90: %fieldnames=&Apache::lonmeta::fieldnames();
1.43 matthew 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'});
1.113 ! www 140: # &Apache::lonnet::logthis("Hrrm $ENV{'form.acts'} -- $verify_title");
1.108 albertel 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.112 www 678: &dynmetaread($uri);
1.1 www 679: }
1.91 taceyjo1 680: return @list=&match_ext($r,@list);
1.1 www 681: }
682:
1.112 www 683: sub dynmetaread {
684: my $uri=shift;
685: if (($hash{'display_attrs_8'}==1) || ($hash{'display_attrs_11'}==1)) {
686: %dynhash=
687: (%dynhash,&Apache::lonmeta::get_dynamic_metadata_from_sql($uri));
688: }
689: }
690:
1.40 matthew 691: sub initdebug {
692: return <<ENDJS;
693: <script>
694: var debugging = true;
695: if (debugging) {
696: var debuggingWindow = window.open('','Debug','width=400,height=300',true);
697: }
698:
699: function output(text) {
700: if (debugging) {
701: debuggingWindow.document.writeln(text);
702: }
703: }
704: output("<html><head><title>Debugging Window</title></head><body><pre>");
705: </script>
706: ENDJS
707: }
708:
709: sub writedebug {
710: my $text = shift;
711: return "<script>output('$text');</script>";
712: }
713:
1.17 harris41 714: # -------------------- filters out files based on extensions (returns an array)
1.1 www 715: sub match_ext {
716: my ($r,@packlist)=@_;
717: my @trimlist;
718: my $nextline;
719: my @fileext;
720: my $dirptr=16384;
721:
1.2 harris41 722: foreach my $line (@packlist) {
723: chomp $line;
724: $line =~ s/^\/home\/httpd\/html//;
725: my @unpackline = split (/\&/,$line);
1.45 ng 726: next if ($unpackline[0] eq '.');
727: next if ($unpackline[0] eq '..');
1.2 harris41 728: my @filecom = split (/\./,$unpackline[0]);
729: my $fext = pop(@filecom);
1.96 www 730: my $fnptr = ($unpackline[3]&$dirptr) || ($fext=~/\.(page|sequence)$/);
1.2 harris41 731: if ($fnptr == 0 and $unpackline[3] ne "") {
1.28 harris41 732: my $embstyle = &Apache::loncommon::fileembstyle($fext);
1.25 matthew 733: push @trimlist,$line if (defined($embstyle) &&
1.32 harris41 734: ($embstyle ne 'hdn' or $fext eq 'meta'));
1.1 www 735: } else {
1.2 harris41 736: push @trimlist,$line;
1.1 www 737: }
738: }
1.80 albertel 739: @trimlist = sort {uc($a) cmp uc($b)} (@trimlist);
1.1 www 740: return @trimlist;
741: }
742:
1.17 harris41 743: # ------------------------------- displays one line in appropriate table format
1.23 harris41 744: sub display_line {
1.16 harris41 745: my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
1.53 albertel 746: my (@pathfn, $fndir);
1.97 www 747: # there could be relative paths (files actually belonging into this directory)
748: # or absolute paths (for example, from sequences)
749: my $absolute;
750: my $pathprefix;
1.107 albertel 751: if ($line=~m|^/res/| && $startdir ne '') {
1.97 www 752: $absolute=1;
753: $pathprefix='';
754: } else {
755: $absolute=0;
756: $pathprefix=$startdir;
757: }
1.1 www 758: my $dirptr=16384;
759: my $fileclr="#ffffe6";
1.45 ng 760: my $iconpath= $r->dir_config('lonIconsURL') . '/';
1.1 www 761:
762: my @filecom = split (/\&/,$line);
763: my @pathcom = split (/\//,$filecom[0]);
764: my $listname = $pathcom[scalar(@pathcom)-1];
765: my $fnptr = $filecom[3]&$dirptr;
1.77 www 766: my $msg = &mt('View').' '.$filecom[0].' '.&mt('resources');
767: $msg = &mt('Close').' '.$filecom[0].' '.&mt('directory') if $diropen eq 'opened';
1.1 www 768:
1.45 ng 769: my $tabtag='</td>';
1.1 www 770: my $i=0;
1.109 taceyjo1 771: while ($i<=11) {
1.45 ng 772: $tabtag=join('',$tabtag,"<td> </td>")
1.17 harris41 773: if $hash{'display_attrs_'.$i} == 1;
1.1 www 774: $i++;
775: }
1.63 ng 776: my $valign = ($hash{'display_attrs_7'} == 1 ? 'top' : 'bottom');
1.17 harris41 777:
778: # display uplink arrow
1.45 ng 779: if ($filecom[1] eq 'viewOneUp') {
1.98 www 780: my $updir=$startdir;
781: # -------------- Filter out sequence containment in crumbs and "recent folders"
782: $updir='/'.(split(/\.(page|sequence)\/\//,$startdir))[-1];
783: $updir=~s/\/+/\//g;
784:
1.70 ng 785: $r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
786: $r->print("<td>\n");
1.98 www 787: $r->print ('<form method="post" name="dirpathUP" action="'.$updir.
1.16 harris41 788: '/" '.
1.17 harris41 789: 'onSubmit="return rep_dirpath(\'UP\','.
790: 'document.forms.fileattr.acts.value)" '.
1.16 harris41 791: 'enctype="application/x-www-form-urlencoded"'.
792: '>'."\n");
1.17 harris41 793: $r->print ('<input type=hidden name=openuri value="'.
794: $startdir.'">'."\n");
1.16 harris41 795: $r->print ('<input type="hidden" name="acts" value="">'."\n");
1.13 ng 796: $r->print ('<input src="'.$iconpath.'arrow_up.gif"');
1.17 harris41 797: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
798: "\n");
1.77 www 799: $r->print(&mt("Up")." $tabtag</tr></form>\n");
1.13 ng 800: return OK;
801: }
1.97 www 802: # Do we have permission to look at this?
803:
804: if($filecom[15] ne '1') { return OK if (!&Apache::lonnet::allowed('bre',$pathprefix.$filecom[0])); }
805:
806: # make absolute links appear on different background
1.112 www 807: if ($absolute) { $fileclr='#ccdd99'; }
1.17 harris41 808:
809: # display domain
1.45 ng 810: if ($filecom[1] eq 'domain') {
1.88 www 811: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
812: if ($ENV{'form.dirPointer'} eq "on");
1.70 ng 813: $r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
814: $r->print("<td>");
1.73 albertel 815: &begin_form ($r,$filecom[0]);
816: my $anchor = $filecom[0];
1.3 harris41 817: $anchor =~ s/\///g;
1.13 ng 818: $r->print ('<a name="'.$anchor.'">');
1.16 harris41 819: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 820: $r->print ('<input src="'.$iconpath.'folder_pointer_'.
821: $diropen.'.gif"');
822: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
823: "\n");
824: $r->print ('<a href="javascript:gothere(\''.$filecom[0].
1.73 albertel 825: '\')"><img src="'.$iconpath.'server.gif"');
1.17 harris41 826: $r->print (' border="0" /></a>'."\n");
1.77 www 827: $r->print (&mt("Domain")." - $listname ");
1.60 albertel 828: if ($Apache::lonnet::domaindescription{$listname}) {
829: $r->print("(".$Apache::lonnet::domaindescription{$listname}.
830: ")");
831: }
832: $r->print (" $tabtag</tr></form>\n");
1.1 www 833: return OK;
1.17 harris41 834:
835: # display user directory
1.1 www 836: }
1.45 ng 837: if ($filecom[1] eq 'user') {
1.70 ng 838: $r->print("<tr valign=$valign bgcolor=$fileclr>$extrafield");
839: $r->print("<td nowrap>\n");
1.2 harris41 840: my $curdir = $startdir.$filecom[0].'/';
1.3 harris41 841: my $anchor = $curdir;
842: $anchor =~ s/\///g;
1.13 ng 843: &begin_form ($r,$curdir);
1.17 harris41 844: $r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
845: 'whitespace1.gif" border="0" />'."\n");
1.16 harris41 846: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 847: $r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
848: '.gif"');
849: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
850: "\n");
851: $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
852: $iconpath.'quill.gif border="0" name="'.$msg.
853: '" height="22" /></a>');
1.60 albertel 854: my $domain=(split(m|/|,$startdir))[2];
855: my $plainname=&Apache::loncommon::plainname($listname,$domain);
856: $r->print ($listname);
857: if (defined($plainname) && $plainname) { $r->print(" ($plainname) "); }
858: $r->print ($tabtag.'</tr></form>'."\n");
1.1 www 859: return OK;
860: }
1.17 harris41 861:
1.1 www 862: # display file
1.97 www 863: if (($fnptr == 0 and $filecom[3] ne '') or $absolute) {
864: my $filelink = $pathprefix.$filecom[0];
1.1 www 865: my @file_ext = split (/\./,$listname);
1.25 matthew 866: my $curfext = $file_ext[-1];
1.40 matthew 867: if (@Omit) {
868: foreach (@Omit) { return OK if ($curfext eq $_); }
869: }
870: if (@Only) {
871: my $skip = 1;
872: foreach (@Only) { $skip = 0 if ($curfext eq $_); }
873: return OK if ($skip > 0);
874: }
1.25 matthew 875: # Set the icon for the file
1.84 albertel 876: my $iconname = &Apache::loncommon::icon($listname);
1.70 ng 877: $r->print("<tr valign='$valign' bgcolor=$fileclr><td nowrap>");
1.104 albertel 878:
879: my $metafile = $Apache::lonnet::perlvar{'lonDocRoot'}.$pathprefix.
880: $filecom[0].'.meta';
881: if (-e $metafile) {
882: $metafile=1;
883: } else {
884: $metafile=0;
885: }
1.7 harris41 886: if ($ENV{'form.catalogmode'} eq 'interactive') {
1.35 matthew 887: $r->print("<a href=\"javascript:select_data(\'",
1.108 albertel 888: $filelink,"')\">");
1.17 harris41 889: $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
890: "\n");
1.70 ng 891: $r->print("</td><td nowrap>");
1.95 www 892: } elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
1.8 harris41 893: $r->print("<form name='form$fnum'>\n");
894: $r->print("<input type='checkbox' name='filelink"."' ".
1.16 harris41 895: "value='$filelink' onClick='".
896: "javascript:queue(\"form$fnum\")' ");
897: if ($hash{'store_'.$filelink}) {
898: $r->print("checked");
899: }
900: $r->print(">\n");
1.8 harris41 901: $r->print("</form>\n");
1.70 ng 902: $r->print("</td><td nowrap>");
1.16 harris41 903: $hash{"pre_${fnum}_link"}=$filelink;
1.8 harris41 904: $fnum++;
1.7 harris41 905: }
1.95 www 906: # Form to open or close sequences
907: if ($filelink=~/\.(page|sequence)$/) {
908: my $curdir = $startdir.$filecom[0].'/';
909: my $anchor = $curdir;
910: $anchor =~ s/\///g;
911: &begin_form($r,$curdir);
912: $indent--;
913: }
914: # General indentation
1.12 ng 915: if ($indent > 0 and $indent < 11) {
1.17 harris41 916: $r->print("<img src=",$iconpath,"whitespace",$indent,
917: ".gif border='0' />\n");
1.11 ng 918: } elsif ($indent >0) {
1.4 harris41 919: my $ten = int($indent/10.);
920: my $rem = $indent%10.0;
921: my $count = 0;
922: while ($count < $ten) {
1.17 harris41 923: $r->print("<img src=",$iconpath,
924: "whitespace10.gif border='0' />\n");
1.1 www 925: $count++;
1.4 harris41 926: }
1.17 harris41 927: $r->print("<img src=",$iconpath,"whitespace",$rem,
928: ".gif border='0' />\n") if $rem > 0;
1.1 www 929: }
1.95 www 930: # Sequence open/close icon
931: if ($filelink=~/\.(page|sequence)$/) {
932: my $curdir = $startdir.$filecom[0].'/';
933: my $anchor = $curdir;
934: $anchor =~ s/\///g;
935: $r->print ('<input type="hidden" name="acts" value="">');
936: $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
937: 'folder_pointer_'.$diropen.'.gif"');
938: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
939: "\n");
940: }
941: # Filetype icons
1.84 albertel 942: $r->print("<img src='$iconname' border='0' />\n");
1.95 www 943: # Close form to open/close sequence
944: if ($filelink=~/\.(page|sequence)$/) {
945: $r->print('</form>');
946: }
1.17 harris41 947: $r->print (" <a href=\"javascript:openWindow('".$filelink.
1.69 www 948: "', 'previewfile', '450', '500', 'no', 'yes','yes')\";".
1.17 harris41 949: " TARGET=_self>$listname</a> ");
950:
951: $r->print (" (<a href=\"javascript:openWindow('".$filelink.
1.71 ng 952: ".meta', 'metadatafile', '500', '550', 'no', 'yes','no')\"; ".
1.104 albertel 953: "TARGET=_self>metadata</a>) ");
1.7 harris41 954: $r->print("</td>\n");
1.45 ng 955: if ($hash{'display_attrs_0'} == 1) {
1.104 albertel 956: my $title = &Apache::lonnet::gettitle($filelink,'title');
1.70 ng 957: $r->print('<td> '.($title eq '' ? ' ' : $title).
1.45 ng 958: ' </td>'."\n");
959: }
1.70 ng 960: $r->print('<td align=right> ',
1.17 harris41 961: $filecom[8]," </td>\n")
1.45 ng 962: if $hash{'display_attrs_1'} == 1;
1.70 ng 963: $r->print('<td> '.
1.17 harris41 964: (localtime($filecom[9]))." </td>\n")
1.45 ng 965: if $hash{'display_attrs_2'} == 1;
1.70 ng 966: $r->print('<td> '.
1.17 harris41 967: (localtime($filecom[10]))." </td>\n")
1.45 ng 968: if $hash{'display_attrs_3'} == 1;
1.2 harris41 969:
1.45 ng 970: if ($hash{'display_attrs_4'} == 1) {
1.104 albertel 971: my $author = &Apache::lonnet::metadata($filelink,'author');
1.70 ng 972: $r->print('<td> '.($author eq '' ? ' ' : $author).
1.17 harris41 973: " </td>\n");
1.2 harris41 974: }
1.45 ng 975: if ($hash{'display_attrs_5'} == 1) {
1.104 albertel 976: my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
1.45 ng 977: # $keywords = ' ' if (!$keywords);
1.70 ng 978: $r->print('<td> '.($keywords eq '' ? ' ' : $keywords).
1.17 harris41 979: " </td>\n");
1.2 harris41 980: }
1.109 taceyjo1 981: #'
982:
1.45 ng 983: if ($hash{'display_attrs_6'} == 1) {
1.104 albertel 984: my $lang = &Apache::lonnet::metadata($filelink,'language');
1.28 harris41 985: $lang = &Apache::loncommon::languagedescription($lang);
1.70 ng 986: $r->print('<td> '.($lang eq '' ? ' ' : $lang).
1.17 harris41 987: " </td>\n");
1.2 harris41 988: }
1.63 ng 989: if ($hash{'display_attrs_7'} == 1) {
1.56 www 990: my $output='';
1.57 www 991: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
992: if ($embstyle eq 'ssi') {
1.89 www 993: my $cache=$Apache::lonnet::perlvar{'lonDocRoot'}.$filelink.
994: '.tmp';
995: if ((!$ENV{'form.updatedisplay'}) &&
996: (-e $cache)) {
997: open(FH,$cache);
998: $output=join("\n",<FH>);
999: close(FH);
1000: } else {
1001: $output=&Apache::lonnet::ssi_body($filelink);
1002: open(FH,">$cache");
1003: print FH $output;
1004: close(FH);
1005: }
1006: $output='<font size="-2">'.$output.'</font>';
1.57 www 1007: } elsif ($embstyle eq 'img') {
1008: $output='<img src="'.$filelink.'" />';
1.58 www 1009: } elsif ($filelink=~/^\/res\/(\w+)\/(\w+)\//) {
1010: $output='<img src="http://'.
1011: $Apache::lonnet::hostname{&Apache::lonnet::homeserver($2,$1)}.
1012: '/cgi-bin/thumbnail.gif?url='.$filelink.'" />';
1.57 www 1013: }
1.70 ng 1014: $r->print('<td> '.($output eq '' ? ' ':$output).
1.56 www 1015: " </td>\n");
1016: }
1.70 ng 1017: if ($hash{'display_attrs_8'} == 1) {
1.111 www 1018: # statistics
1.112 www 1019: $r->print("<td>");
1020: if ($dynhash{$filelink}->{'stdno'}) {
1021: $r->print(&mt('Number of students: ').
1022: $dynhash{$filelink}->{'stdno'}.'<br />');
1023: }
1024: $r->print(" </td>\n");
1.111 www 1025:
1.70 ng 1026: }
1.109 taceyjo1 1027: if ($hash{'display_attrs_10'} == 1) {
1028: my $source = &Apache::lonnet::metadata($filelink,'sourceavail');
1.110 albertel 1029: if($source eq 'open') {
1030: my $sourcelink = &Apache::lonsource::make_link($filelink);
1031: $r->print('<td>'."<a href=\"javascript:openWindow('".$sourcelink.
1032: "', 'previewsource', '700', '700', 'no', 'yes','yes')\";".
1033: " TARGET=_self>Yes</a> "."</td>\n");
1034: } else { #A cuddled else. :P
1.111 www 1035: $r->print("<td> </td>\n");
1.110 albertel 1036: }
1.109 taceyjo1 1037: }
1.111 www 1038: if ($hash{'display_attrs_11'} == 1) {
1039: # links
1.113 ! www 1040: $r->print('<td>');
! 1041: &dynmetaprint($r,$filelink,'goto_list');
! 1042: &dynmetaprint($r,$filelink,'comefrom_list');
! 1043: &dynmetaprint($r,$filelink,'sequsage_list');
! 1044: my $dependencies=&Apache::lonnet::metadata($filelink,'dependencies');
! 1045: if ($dependencies=~/\w/) {
! 1046: $r->print(&mt('Links to:').
! 1047: &Apache::lonmeta::prettyprint('linkto_list',&Apache::lonnet::metadata($filelink,'dependencies'),
! 1048: (($ENV{'form.catalogmode'} ne 'groupimport')?'preview':''),
! 1049: '',
! 1050: (($ENV{'form.catalogmode'} eq 'groupimport')?'document.forms.fileattr':''),1));
! 1051: }
! 1052: $r->print('</td>');
! 1053: }
1.1 www 1054: $r->print("</tr>\n");
1055: }
1.17 harris41 1056:
1.2 harris41 1057: # -- display directory
1.1 www 1058: if ($fnptr == $dirptr) {
1.2 harris41 1059: my $curdir = $startdir.$filecom[0].'/';
1.3 harris41 1060: my $anchor = $curdir;
1061: $anchor =~ s/\///g;
1.63 ng 1062: $r->print("<tr bgcolor=$fileclr>$extrafield<td valign=$valign>");
1.2 harris41 1063: &begin_form ($r,$curdir);
1.4 harris41 1064: my $indentm1 = $indent-1;
1.11 ng 1065: if ($indentm1 < 11 and $indentm1 > 0) {
1.17 harris41 1066: $r->print("<img src=",$iconpath,"whitespace",$indentm1,
1067: ".gif border='0' />\n");
1.4 harris41 1068: } else {
1069: my $ten = int($indentm1/10.);
1070: my $rem = $indentm1%10.0;
1071: my $count = 0;
1072: while ($count < $ten) {
1.17 harris41 1073: $r->print ("<img src=",$iconpath
1074: ,"whitespace10.gif border='0' />\n");
1.12 ng 1075: $count++;
1.4 harris41 1076: }
1.17 harris41 1077: $r->print ("<img src=",$iconpath,"whitespace",$rem,
1078: ".gif border='0' />\n") if $rem > 0;
1.1 www 1079: }
1.16 harris41 1080: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 1081: $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
1082: 'folder_pointer_'.$diropen.'.gif"');
1083: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
1084: "\n");
1085: $r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
1086: $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
1087: "\n");
1.86 www 1088: $r->print ("$listname</td>\n");
1089: # Attributes
1090: my $filelink = $startdir.$filecom[0].'/default';
1091:
1092: if ($hash{'display_attrs_0'} == 1) {
1093: my $title = &Apache::lonnet::gettitle($filelink,'title');
1094: $r->print('<td> '.($title eq '' ? ' ' : $title).
1095: ' </td>'."\n");
1096: }
1097: $r->print('<td align=right> ',
1098: $filecom[8]," </td>\n")
1099: if $hash{'display_attrs_1'} == 1;
1100: $r->print('<td> '.
1101: (localtime($filecom[9]))." </td>\n")
1102: if $hash{'display_attrs_2'} == 1;
1103: $r->print('<td> '.
1104: (localtime($filecom[10]))." </td>\n")
1105: if $hash{'display_attrs_3'} == 1;
1106:
1107: if ($hash{'display_attrs_4'} == 1) {
1108: my $author = &Apache::lonnet::metadata($filelink,'author');
1109: $r->print('<td> '.($author eq '' ? ' ' : $author).
1110: " </td>\n");
1111: }
1112: if ($hash{'display_attrs_5'} == 1) {
1113: my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
1114: # $keywords = ' ' if (!$keywords);
1115: $r->print('<td> '.($keywords eq '' ? ' ' : $keywords).
1116: " </td>\n");
1117: }
1118: if ($hash{'display_attrs_6'} == 1) {
1119: my $lang = &Apache::lonnet::metadata($filelink,'language');
1120: $lang = &Apache::loncommon::languagedescription($lang);
1121: $r->print('<td> '.($lang eq '' ? ' ' : $lang).
1122: " </td>\n");
1123: }
1124: if ($hash{'display_attrs_7'} == 1) {
1125: $r->print('<td> </td>');
1126: }
1127: if ($hash{'display_attrs_8'} == 1) {
1128: $r->print('<td> </td>');
1129: }
1.109 taceyjo1 1130: if ($hash{'display_attrs_10'} == 1) {
1131: $r->print('<td> </td>');
1132: }
1.111 www 1133: if ($hash{'display_attrs_11'} == 1) {
1134: $r->print('<td> </td>');
1135: }
1.86 www 1136: $r->print('</form></tr>');
1.1 www 1137: }
1.2 harris41 1138:
1.1 www 1139: }
1140:
1.113 ! www 1141: sub dynmetaprint {
! 1142: my ($r,$filelink,$item)=@_;
! 1143: if ($dynhash{$filelink}->{$item}) {
! 1144: $r->print($fieldnames{$item}.': '.
! 1145: &Apache::lonmeta::prettyprint($item,
! 1146: $dynhash{$filelink}->{$item},
! 1147: (($ENV{'form.catalogmode'} ne 'groupimport')?'preview':''),
! 1148: '',
! 1149: (($ENV{'form.catalogmode'} eq 'groupimport')?'document.forms.fileattr':''),1));
! 1150: }
! 1151: }
! 1152:
1.14 harris41 1153: # ------------------- prints the beginning of a form for directory or file link
1.1 www 1154: sub begin_form {
1155: my ($r,$uri) = @_;
1.3 harris41 1156: my $anchor = $uri;
1157: $anchor =~ s/\///g;
1.17 harris41 1158: $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
1159: '#'.$anchor.
1160: '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
1161: ',document.forms.fileattr.acts.value)" '.
1.16 harris41 1162: 'enctype="application/x-www-form-urlencoded">'."\n");
1.17 harris41 1163: $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
1164: "\n");
1.88 www 1165: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
1.16 harris41 1166: $dnum++;
1.17 harris41 1167: }
1168:
1169: # --------- settings whenever the user causes the indexer window to be launched
1170: sub start_fresh_session {
1.48 matthew 1171: delete $hash{'form.catalogmode'};
1172: delete $hash{'form.mode'};
1173: delete $hash{'form.form'};
1174: delete $hash{'form.element'};
1175: delete $hash{'form.omit'};
1176: delete $hash{'form.only'};
1.27 harris41 1177: foreach (keys %hash) {
1.48 matthew 1178: delete $hash{$_} if (/^(pre_|store)/);
1.27 harris41 1179: }
1.1 www 1180: }
1181:
1.35 matthew 1182: # ------------------------------------------------------------------- setvalues
1183: sub setvalues {
1184: # setvalues is used in registerurl to synchronize the database
1185: # hash and environment hashes
1186: my ($H1,$h1key,$H2,$h2key) =@_;
1187: #
1188: if (exists $H2->{$h2key}) {
1189: $H1->{$h1key} = $H2->{$h2key};
1190: } elsif (exists $H1->{$h1key}) {
1191: $H2->{$h2key} = $H1->{$h1key};
1192: }
1193: }
1194:
1.1 www 1195: 1;
1.54 www 1196:
1197: sub cleanup {
1.55 www 1198: if (tied(%hash)){
1199: &Apache::lonnet::logthis('Cleanup indexer: hash');
1200: }
1.54 www 1201: }
1.23 harris41 1202:
1203: =head1 NAME
1204:
1205: Apache::lonindexer - mod_perl module for cross server filesystem browsing
1206:
1207: =head1 SYNOPSIS
1208:
1209: Invoked by /etc/httpd/conf/srm.conf:
1210:
1211: <LocationMatch "^/res.*/$">
1212: SetHandler perl-script
1213: PerlHandler Apache::lonindexer
1214: </LocationMatch>
1215:
1216: =head1 INTRODUCTION
1217:
1218: This module enables a scheme of browsing across a cross server.
1219:
1220: This is part of the LearningOnline Network with CAPA project
1221: described at http://www.lon-capa.org.
1222:
1223: =head1 BEGIN SUBROUTINE
1224:
1225: This routine is only run once after compilation.
1226:
1227: =over 4
1228:
1229: =item *
1230:
1231: Initializes %language hash table.
1232:
1233: =back
1234:
1235: =head1 HANDLER SUBROUTINE
1236:
1237: This routine is called by Apache and mod_perl.
1238:
1239: =over 4
1240:
1241: =item *
1242:
1243: read in machine configuration variables
1244:
1245: =item *
1246:
1247: see if called from an interactive mode
1248:
1249: =item *
1250:
1251: refresh environment with user database values (in %hash)
1252:
1253: =item *
1254:
1255: define extra fields and buttons in case of special mode
1256:
1257: =item *
1258:
1259: set catalogmodefunctions to have extra needed javascript functionality
1260:
1261: =item *
1262:
1263: print header
1264:
1265: =item *
1266:
1267: evaluate actions from previous page (both cumulatively and chronologically)
1268:
1269: =item *
1270:
1271: output title
1272:
1273: =item *
1274:
1275: get state of file attributes to be showing
1276:
1277: =item *
1278:
1279: output state of file attributes to be showing
1280:
1281: =item *
1282:
1283: output starting row to the indexed file/directory hierarchy
1284:
1285: =item *
1286:
1287: read in what directories have previously been set to "open"
1288:
1289: =item *
1290:
1291: if not at top level, provide an uplink arrow
1292:
1293: =item *
1294:
1295: recursively go through all the directories and output as appropriate
1296:
1297: =item *
1298:
1299: information useful for group import
1300:
1301: =item *
1302:
1303: end the tables
1304:
1305: =item *
1306:
1307: end the output and return
1308:
1309: =back
1310:
1311: =head1 OTHER SUBROUTINES
1312:
1313: =over 4
1314:
1315: =item *
1316:
1317: scanDir - recursive scan of a directory
1318:
1319: =item *
1320:
1321: get_list - get complete matched list based on the uri (returns an array)
1322:
1323: =item *
1324:
1325: match_ext - filters out files based on extensions (returns an array)
1326:
1327: =item *
1328:
1329: display_line - displays one line in appropriate table format
1330:
1331: =item *
1332:
1333: begin_form - prints the beginning of a form for directory or file link
1334:
1335: =item *
1336:
1337: start_fresh_session - settings whenever the user causes the indexer window
1338: to be launched
1339:
1340: =back
1341:
1342: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>