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