Annotation of loncom/interface/lonindexer.pm, revision 1.125
1.1 www 1: # The LearningOnline Network with CAPA
1.24 harris41 2: # Directory Indexer
3: #
1.125 ! foxr 4: # $Id: lonindexer.pm,v 1.124 2004/09/25 17:58:01 matthew Exp $
1.24 harris41 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
1.14 harris41 14: #
1.24 harris41 15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
1.14 harris41 27: #
1.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.117 www 63: my %dynread; # hash of directories already read for dynamic metadata
1.113 www 64: my %fieldnames; # Metadata fieldnames
1.17 harris41 65: # ----- Values which are set by the handler subroutine and are accessible to
66: # ----- other methods.
67: my $extrafield; # default extra table cell
68: my $fnum; # file counter
69: my $dnum; # directory counter
1.1 www 70:
1.40 matthew 71: # ----- Used to include or exclude files with certain extensions.
1.43 matthew 72: my @Only = ();
1.40 matthew 73: my @Omit = ();
74:
75:
1.125 ! foxr 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:
1.23 harris41 103: # ----------------------------- Handling routine called via Apache and mod_perl
1.1 www 104: sub handler {
105: my $r = shift;
1.67 matthew 106: my $c = $r->connection();
1.76 www 107: &Apache::loncommon::content_type($r,'text/html');
1.50 albertel 108: &Apache::loncommon::no_cache($r);
1.1 www 109: $r->send_http_header;
110: return OK if $r->header_only;
1.9 harris41 111: $fnum=0;
1.16 harris41 112: $dnum=0;
1.17 harris41 113:
1.43 matthew 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);
1.113 www 118: %fieldnames=&Apache::lonmeta::fieldnames();
1.43 matthew 119:
1.23 harris41 120: # ------------------------------------- read in machine configuration variables
1.10 harris41 121: my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.1 www 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:
1.7 harris41 130: my $fileclr='#ffffe6';
1.15 harris41 131: my $line;
132: my (@attrchk,@openpath);
133: my $uri=$r->uri;
134:
1.7 harris41 135: # -------------------------------------- see if called from an interactive mode
1.35 matthew 136: # Get the parameters from the query string
1.36 matthew 137: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.40 matthew 138: ['catalogmode','launch','acts','mode','form','element',
1.79 albertel 139: 'only','omit','titleelement']);
1.35 matthew 140: #-------------------------------------------------------------------
1.17 harris41 141: my $closebutton='';
1.7 harris41 142: my $groupimportbutton='';
143: my $colspan='';
1.14 harris41 144:
145: $extrafield='';
1.17 harris41 146: my $diropendb =
1.66 albertel 147: "/home/httpd/perl/tmp/$ENV{'user.domain'}_$ENV{'user.name'}_indexer.db";
1.67 matthew 148: %hash = ();
1.68 albertel 149: {
150: my %dbfile;
1.87 www 151: if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_READER(),0640)) {
1.68 albertel 152: while(my($key,$value)=each(%dbfile)) {
153: $hash{$key}=$value;
154: }
155: untie(%dbfile);
156: }
157: }
158: {
1.15 harris41 159: if ($ENV{'form.launch'} eq '1') {
1.17 harris41 160: &start_fresh_session();
1.105 taceyjo1 161: }
162: #Hijack lonindexer to verify a title and be close down.
163: if ($ENV{'form.launch'} eq '2') {
1.108 albertel 164: $r->content_type('text/html');
165: my $extra='';
1.118 albertel 166: if (defined($ENV{'form.titleelement'}) &&
167: $ENV{'form.titleelement'} ne '') {
1.108 albertel 168: my $verify_title = &Apache::lonnet::gettitle($ENV{'form.acts'});
1.113 www 169: # &Apache::lonnet::logthis("Hrrm $ENV{'form.acts'} -- $verify_title");
1.108 albertel 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);
1.105 taceyjo1 174: <html>
175: <script type="text/javascript">
176: function load() {
1.125 ! foxr 177: window.opener.document.forms["$ENV{'form.form'}"]
! 178: .elements["$ENV{'form.element'}"]
! 179: .value='$ENV{'form.acts'}';
1.108 albertel 180: $extra
1.105 taceyjo1 181: window.close();
182: }
183: </script>
184: <body onLoad=load();>
185: </body>
186: </html>
187: ENDSUBM
1.108 albertel 188: return OK;
1.105 taceyjo1 189: }
190:
1.17 harris41 191: # -------------------- refresh environment with user database values (in %hash)
1.48 matthew 192: &setvalues(\%hash,'form.catalogmode',\%ENV,'form.catalogmode' );
1.15 harris41 193:
1.17 harris41 194: # --------------------- define extra fields and buttons in case of special mode
1.15 harris41 195: if ($ENV{'form.catalogmode'} eq 'interactive') {
196: $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
197: '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17 harris41 198: ' border="0" /></td>';
1.15 harris41 199: $colspan=" colspan='2' ";
1.77 www 200: my $cl=&mt('Close');
1.15 harris41 201: $closebutton=<<END;
1.77 www 202: <input type="button" name="close" value='$cl' onClick="self.close()">
1.7 harris41 203: END
1.16 harris41 204: }
1.15 harris41 205: elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
206: $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
207: '<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17 harris41 208: ' border="0" /></td>';
1.15 harris41 209: $colspan=" colspan='2' ";
1.77 www 210: my $cl=&mt('Close');
1.123 matthew 211: my $gi=&mt('Import');
1.15 harris41 212: $closebutton=<<END;
1.77 www 213: <input type="button" name="close" value='$cl' onClick="self.close()">
1.7 harris41 214: END
1.15 harris41 215: $groupimportbutton=<<END;
1.77 www 216: <input type="button" name="groupimport" value='$gi'
1.17 harris41 217: onClick="javascript:select_group()">
1.7 harris41 218: END
1.15 harris41 219: }
1.35 matthew 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.
1.91 taceyjo1 228: #&Apache::lonxml::debug('Checking mode, form, element');
1.79 albertel 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' );
1.35 matthew 235:
1.40 matthew 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:
1.35 matthew 244: my $mode = $ENV{'form.mode'};
1.79 albertel 245: my ($form,$element,$titleelement);
1.39 matthew 246: if ($mode eq 'edit' || $mode eq 'parmset') {
1.79 albertel 247: $form = $ENV{'form.form'};
248: $element = $ENV{'form.element'};
249: $titleelement = $ENV{'form.titleelement'};
1.35 matthew 250: }
1.90 taceyjo1 251: #&Apache::lonxml::debug("mode=$mode form=$form element=$element titleelement=$titleelement");
1.17 harris41 252: # ------ set catalogmodefunctions to have extra needed javascript functionality
1.15 harris41 253: my $catalogmodefunctions='';
254: if ($ENV{'form.catalogmode'} eq 'interactive' or
255: $ENV{'form.catalogmode'} eq 'groupimport') {
1.35 matthew 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.
1.41 www 260:
261: #
262: # There is now also mode "simple", which is for the simple version of the rat
263: #
264: #
1.39 matthew 265: if (!defined($mode) || ($mode ne 'edit' && $mode ne 'parmset')) {
1.40 matthew 266: my $location = "/adm/groupsort?catalogmode=groupimport&";
1.41 www 267: $location .= "mode=".$mode."&";
1.40 matthew 268: $location .= "acts=";
1.35 matthew 269: $catalogmodefunctions=<<"END";
1.108 albertel 270: function select_data(url) {
1.7 harris41 271: changeURL(url);
1.8 harris41 272: self.close();
273: }
274: function select_group() {
1.40 matthew 275: window.location="$location"+document.forms.fileattr.acts.value;
1.16 harris41 276: }
1.35 matthew 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: }
1.7 harris41 282: }
283: }
1.35 matthew 284: END
1.39 matthew 285: } elsif ($mode eq 'edit') { # we are in 'edit' mode
1.40 matthew 286: my $location = "/adm/groupsort?catalogmode=interactive&";
287: $location .= "form=$form&element=$element&mode=edit&acts=";
1.35 matthew 288: $catalogmodefunctions=<<END;
289: // mode = $mode
1.108 albertel 290: function select_data(url) {
291: var location = "/res/?launch=2&form=$form&element=$element&titleelement=$titleelement&acts=" + url;
1.105 taceyjo1 292: window.location=location;
1.35 matthew 293: }
294: function select_group() {
1.40 matthew 295: window.location="$location"+document.forms.fileattr.acts.value;
1.35 matthew 296: }
297:
1.7 harris41 298: function changeURL(val) {
1.35 matthew 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);
1.7 harris41 303: }
304: }
305: END
1.79 albertel 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: }
1.39 matthew 319: } elsif ($mode eq 'parmset') {
1.40 matthew 320: my $location = "/adm/groupsort?catalogmode=interactive&";
321: $location .= "form=$form&element=$element&mode=parmset&acts=";
1.39 matthew 322: $catalogmodefunctions=<<END;
323: // mode = $mode
1.108 albertel 324: function select_data(url) {
1.39 matthew 325: changeURL(url);
326: self.close();
327: }
328:
329: function select_group() {
1.40 matthew 330: window.location="$location"+document.forms.fileattr.acts.value;
1.39 matthew 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: }
1.15 harris41 346: }
1.38 matthew 347: $catalogmodefunctions.=<<END;
348: var acts='';
349: function rep_dirpath(suffix,val) {
350: eval("document.forms.dirpath"+suffix+".acts.value=val");
351: }
352: END
1.16 harris41 353: if ($ENV{'form.catalogmode'} eq 'groupimport') {
1.38 matthew 354: $catalogmodefunctions.=<<END;
1.16 harris41 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: }
1.17 harris41 369:
1.1 www 370: # ---------------------------------------------------------------- Print Header
1.15 harris41 371: $r->print(<<ENDHEADER);
1.1 www 372: <html>
373: <head>
1.2 harris41 374: <title>The LearningOnline Network With CAPA Directory Browser</title>
1.3 harris41 375:
1.19 harris41 376: <script type="text/javascript">
1.7 harris41 377: $catalogmodefunctions
1.69 www 378: function openWindow(url, wdwName, w, h, toolbar,scrollbar,locationbar) {
1.71 ng 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+",";
1.2 harris41 384: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
1.69 www 385: options += "menubar=no,toolbar="+toolbar+",location="+locationbar+",directories=no";
1.2 harris41 386: var newWin = window.open(url, wdwName, options);
387: newWin.focus();
388: }
1.16 harris41 389: function gothere(val) {
390: window.location=val+'?acts='+document.forms.fileattr.acts.value;
391: }
1.14 harris41 392: </script>
1.3 harris41 393:
1.1 www 394: </head>
395: ENDHEADER
1.74 www 396: my ($headerdom)=($uri=~/^\/res\/(\w+)\//);
397: $r->print(&Apache::loncommon::bodytag('Browse Resources',undef,undef,undef,
398: $headerdom));
1.17 harris41 399: # - Evaluate actions from previous page (both cumulatively and chronologically)
1.16 harris41 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;
1.17 harris41 406: # some initial hashes for working with data
1.27 harris41 407: foreach (@Acts) {
1.16 harris41 408: my ($state,$ref)=split(/a/);
409: $ahash{$ref}=$state;
410: $achash{$ref}=$ac;
411: $ac++;
1.27 harris41 412: }
1.87 www 413: # sorting through the actions and changing the global database hash
1.27 harris41 414: foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
1.16 harris41 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: }
1.27 harris41 428: }
1.17 harris41 429: # deleting the previously cached listing
1.27 harris41 430: foreach (keys %hash) {
1.16 harris41 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: }
1.27 harris41 438: }
1.16 harris41 439: }
440:
1.23 harris41 441: # ---------------------------------- get state of file attributes to be showing
1.87 www 442: if ($ENV{'form.attrs'}) {
1.111 www 443: for (my $i=0; $i<=11; $i++) {
1.6 harris41 444: delete $hash{'display_attrs_'.$i};
445: if ($ENV{'form.attr'.$i} == 1) {
1.45 ng 446: $attrchk[$i] = 'checked';
1.6 harris41 447: $hash{'display_attrs_'.$i} = 1;
448: }
449: }
450: } else {
1.111 www 451: for (my $i=0; $i<=11; $i++) {
1.45 ng 452: $attrchk[$i] = 'checked' if $hash{'display_attrs_'.$i} == 1;
1.6 harris41 453: }
454: }
1.87 www 455:
1.23 harris41 456: # ------------------------------- output state of file attributes to be showing
1.71 ng 457: # All versions has to the last item
458: # since it does not take an extra col
1.77 www 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',
1.78 www 467: 'ln' => 'Language',
1.109 taceyjo1 468: 'sa' => 'Source Available',
1.77 www 469: 'sr' => 'Show resource',
1.111 www 470: 'li' => 'Linked/Related Resources',
1.77 www 471: 'av' => 'All versions',
472: 'ud' => 'Update Display'
473: );
1.15 harris41 474: $r->print(<<END);
1.17 harris41 475: <form method="post" name="fileattr" action="$uri"
476: enctype="application/x-www-form-urlencoded">
1.124 matthew 477: <label><input type="checkbox" name="attr9" value="1" $attrchk[9] onClick="this.form.submit();" /> $lt{'av'}</label>
1.115 www 478: <table border="0">
479: <tr>
1.124 matthew 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>
1.115 www 484: </tr>
485: <tr>
1.124 matthew 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>
1.115 www 490: </tr>
491: <tr>
1.124 matthew 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>
1.115 www 495: <td> </td>
496: </tr>
497: </table>
1.87 www 498: <input type="hidden" name="attrs" value="1" />
499: <input type="submit" name="updatedisplay" value="$lt{'ud'}" />
1.16 harris41 500: <input type="hidden" name="acts" value="" />
1.87 www 501: $closebutton $groupimportbutton
1.1 www 502: END
1.97 www 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;
1.82 www 507: # ---------------------------------------------------------------- Bread crumbs
1.97 www 508: $r->print(&Apache::lonhtmlcommon::crumbs($storeuri,'','',
1.87 www 509: (($ENV{'form.catalogmode'} eq 'groupimport')?
510: 'document.forms.fileattr':'')).
511: &Apache::lonhtmlcommon::select_recent('residx','resrecent',
1.100 www 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>');
1.85 www 525: # ------------------------------------------------------ Remember where we were
1.97 www 526: &Apache::loncommon::storeresurl($storeuri);
527: &Apache::lonhtmlcommon::store_recent('residx',$storeuri,$storeuri);
1.23 harris41 528: # ----------------- output starting row to the indexed file/directory hierarchy
1.15 harris41 529: my $titleclr="#ddffff";
1.40 matthew 530: # $r->print(&initdebug());
531: # $r->print(&writedebug("Omit:@Omit")) if (@Omit);
532: # $r->print(&writedebug("Only:@Only")) if (@Only);
1.46 ng 533: $r->print("<table width='100\%' border=0><tr><td bgcolor=#777777>\n");
1.45 ng 534: $r->print("<table width='100\%' border=0><tr bgcolor=$titleclr>\n");
1.77 www 535: $r->print("<td $colspan><b>".&mt('Name')."</b></td>\n");
536: $r->print("<td><b>".&mt('Title')."</b></td>\n")
1.45 ng 537: if ($hash{'display_attrs_0'} == 1);
1.77 www 538: $r->print("<td align=right><b>".&mt("Size")." (".&mt("bytes").") ".
1.45 ng 539: "</b></td>\n") if ($hash{'display_attrs_1'} == 1);
1.77 www 540: $r->print("<td><b>".&mt("Last accessed")."</b></td>\n")
1.17 harris41 541: if ($hash{'display_attrs_2'} == 1);
1.77 www 542: $r->print("<td><b>".&mt("Last modified")."</b></td>\n")
1.17 harris41 543: if ($hash{'display_attrs_3'} == 1);
1.77 www 544: $r->print("<td><b>".&mt("Author(s)")."</b></td>\n")
1.17 harris41 545: if ($hash{'display_attrs_4'} == 1);
1.77 www 546: $r->print("<td><b>".&mt("Keywords")."</b></td>\n")
1.17 harris41 547: if ($hash{'display_attrs_5'} == 1);
1.77 www 548: $r->print("<td><b>".&mt("Language")."</b></td>\n")
1.45 ng 549: if ($hash{'display_attrs_6'} == 1);
1.77 www 550: $r->print("<td><b>".&mt("Usage Statistics")." <br />(".
1.120 matthew 551: &mt("Courses/Network Hits").")</b> ".&mt('updated periodically')."</td>\n")
1.70 ng 552: if ($hash{'display_attrs_8'} == 1);
1.109 taceyjo1 553: $r->print("<td><b>".&mt("Source Available")."</b></td>\n")
554: if ($hash{'display_attrs_10'} == 1);
1.111 www 555: $r->print("<td><b>".&mt("Linked/Related Resources")."</b></td>\n")
556: if ($hash{'display_attrs_11'} == 1);
1.115 www 557: $r->print("<td><b>".&mt("Resource")."</b></td>\n")
558: if ($hash{'display_attrs_7'} == 1);
1.45 ng 559: $r->print('</tr>');
1.5 harris41 560:
1.23 harris41 561: # ----------------- read in what directories have previously been set to "open"
1.27 harris41 562: foreach (keys %hash) {
1.4 harris41 563: if ($_ =~ /^diropen_status_/) {
564: my $key = $_;
565: $key =~ s/^diropen_status_//;
566: $dirs{$key} = $hash{$_};
567: }
1.27 harris41 568: }
1.4 harris41 569:
1.2 harris41 570: if ($ENV{'form.openuri'}) { # take care of review and refresh options
571: my $uri=$ENV{'form.openuri'};
1.4 harris41 572: if (exists($hash{'diropen_status_'.$uri})) {
573: my $cursta = $hash{'diropen_status_'.$uri};
1.2 harris41 574: $dirs{$uri} = 'open';
1.4 harris41 575: $hash{'diropen_status_'.$uri} = 'open';
576: if ($cursta eq 'open') {
577: $dirs{$uri} = 'closed';
578: $hash{'diropen_status_'.$uri} = 'closed';
579: }
1.2 harris41 580: } else {
1.4 harris41 581: $hash{'diropen_status_'.$uri} = 'open';
1.2 harris41 582: $dirs{$uri} = 'open';
583: }
584: }
1.12 ng 585:
586: my $toplevel;
1.13 ng 587: my $indent = 0;
1.12 ng 588: $uri = $uri.'/' if $uri !~ /.*\/$/;
1.17 harris41 589:
1.88 www 590: if ($ENV{'form.dirPointer'} ne 'on') {
591: $hash{'top.level'} = $uri;
592: $toplevel = $uri;
593: } else {
594: $toplevel = $hash{'top.level'};
595: }
1.17 harris41 596:
1.23 harris41 597: # -------------------------------- if not at top level, provide an uplink arrow
1.45 ng 598: if ($toplevel ne '/res/'){
1.13 ng 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;
1.12 ng 605: }
1.17 harris41 606:
1.23 harris41 607: # -------- recursively go through all the directories and output as appropriate
1.16 harris41 608: &scanDir ($r,$toplevel,$indent,\%hash);
1.12 ng 609:
1.23 harris41 610: # ---------------------------- embed hidden information useful for group import
1.8 harris41 611: $r->print("<form name='fnum'>");
612: $r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
1.17 harris41 613:
1.23 harris41 614: # -------------------------------------------------------------- end the tables
1.45 ng 615: $r->print('</table>');
616: $r->print('</td></tr></table>');
1.17 harris41 617:
1.23 harris41 618: # --------------------------------------------------- end the output and return
1.45 ng 619: $r->print('</body></html>'."\n");
1.2 harris41 620: }
1.67 matthew 621: if(! $c->aborted()) {
1.87 www 622: # write back into the temporary file
1.68 albertel 623: my %dbfile;
1.67 matthew 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:
1.1 www 632: return OK;
633: }
1.2 harris41 634:
1.17 harris41 635: # ----------------------------------------------- recursive scan of a directory
1.2 harris41 636: sub scanDir {
1.16 harris41 637: my ($r,$startdir,$indent,$hashref)=@_;
1.67 matthew 638: my $c = $r->connection();
1.3 harris41 639: my ($compuri,$curdir);
640: my $dirptr=16384;
1.90 taceyjo1 641: my $obs;
1.1 www 642: $indent++;
1.2 harris41 643: my %dupdirs = %dirs;
644: my @list=&get_list($r,$startdir);
645: foreach my $line (@list) {
1.67 matthew 646: return if ($c->aborted());
1.90 taceyjo1 647: #This is a kludge, sorry aboot this
1.92 taceyjo1 648: my ($strip,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1.90 taceyjo1 649: next if($strip =~ /.*\.meta$/ | $obs eq '1');
1.18 ng 650: my (@fileparts) = split(/\./,$strip);
1.70 ng 651: if ($hash{'display_attrs_9'} != 1) {
1.95 www 652: # if not all versions to be shown
1.18 ng 653: if (scalar(@fileparts) >= 3) {
654: my $fext = pop @fileparts;
655: my $ov = pop @fileparts;
656: my $fname = join ('.',@fileparts,$fext);
1.75 albertel 657: next if (grep /\Q$fname\E/,@list and $ov =~ /^\d+$/);
1.18 ng 658: }
659: }
660:
1.45 ng 661: if ($dom eq 'domain') {
1.72 albertel 662: # dom list has full path /res/<domain name>/ already
663: $curdir='';
1.73 albertel 664: $compuri = (split(/\&/,$line))[0];
1.2 harris41 665: } else {
1.17 harris41 666: # user, dir & file have name only, i.e., w/o path
1.45 ng 667: $compuri = join('',$startdir,$strip,'/');
1.3 harris41 668: $curdir = $startdir;
1.2 harris41 669: }
1.45 ng 670: my $diropen = 'closed';
1.96 www 671: if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/) or ($compuri=~/\.(sequence|page)\/$/)) {
1.3 harris41 672: while (my ($key,$val)= each %dupdirs) {
1.5 harris41 673: if ($key eq $compuri and $val eq "open") {
1.11 ng 674: $diropen = "opened";
1.53 albertel 675: delete($dupdirs{$key});
676: delete($dirs{$key});
1.5 harris41 677: }
1.3 harris41 678: }
1.1 www 679: }
1.16 harris41 680: &display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
1.45 ng 681: &scanDir ($r,$compuri,$indent) if $diropen eq 'opened';
1.1 www 682: }
683: $indent--;
684: }
685:
1.17 harris41 686: # --------------- get complete matched list based on the uri (returns an array)
1.1 www 687: sub get_list {
688: my ($r,$uri)=@_;
1.97 www 689: my @list=();
1.45 ng 690: (my $luri = $uri) =~ s/\//_/g;
1.87 www 691: if ($ENV{'form.updatedisplay'}) {
1.27 harris41 692: foreach (keys %hash) {
1.4 harris41 693: delete $hash{$_} if ($_ =~ /^dirlist_files_/);
1.121 albertel 694: delete $hash{$_} if ($_ =~ /^dirlist_timestamp_files_/);
1.87 www 695: }
1.2 harris41 696: }
697:
1.121 albertel 698: if (defined($hash{'dirlist_files_'.$luri}) &&
699: $hash{'dirlist_timestamp_files_'.$luri}+600 > (time)) {
1.4 harris41 700: @list = split(/\n/,$hash{'dirlist_files_'.$luri});
1.97 www 701: } elsif ($uri=~/\.(page|sequence)\/$/) {
1.94 www 702: # is a page or a sequence
1.97 www 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: }
1.94 www 710: $hash{'dirlist_files_'.$luri} = join("\n",@list);
1.1 www 711: } else {
1.94 www 712: # is really a directory
1.4 harris41 713: @list = &Apache::lonnet::dirlist($uri);
1.87 www 714: $hash{'dirlist_files_'.$luri} = join("\n",@list);
1.121 albertel 715: $hash{'dirlist_timestamp_files_'.$luri} = time;
1.1 www 716: }
1.91 taceyjo1 717: return @list=&match_ext($r,@list);
1.1 www 718: }
719:
1.112 www 720: sub dynmetaread {
721: my $uri=shift;
722: if (($hash{'display_attrs_8'}==1) || ($hash{'display_attrs_11'}==1)) {
1.117 www 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
1.112 www 734: %dynhash=
735: (%dynhash,&Apache::lonmeta::get_dynamic_metadata_from_sql($uri));
1.117 www 736: # Remember that we got it
737: $dynread{$uri}=1;
1.112 www 738: }
739: }
740:
1.40 matthew 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:
1.17 harris41 764: # -------------------- filters out files based on extensions (returns an array)
1.1 www 765: sub match_ext {
766: my ($r,@packlist)=@_;
767: my @trimlist;
768: my $nextline;
769: my @fileext;
770: my $dirptr=16384;
771:
1.2 harris41 772: foreach my $line (@packlist) {
773: chomp $line;
774: $line =~ s/^\/home\/httpd\/html//;
775: my @unpackline = split (/\&/,$line);
1.45 ng 776: next if ($unpackline[0] eq '.');
777: next if ($unpackline[0] eq '..');
1.2 harris41 778: my @filecom = split (/\./,$unpackline[0]);
779: my $fext = pop(@filecom);
1.96 www 780: my $fnptr = ($unpackline[3]&$dirptr) || ($fext=~/\.(page|sequence)$/);
1.2 harris41 781: if ($fnptr == 0 and $unpackline[3] ne "") {
1.28 harris41 782: my $embstyle = &Apache::loncommon::fileembstyle($fext);
1.25 matthew 783: push @trimlist,$line if (defined($embstyle) &&
1.32 harris41 784: ($embstyle ne 'hdn' or $fext eq 'meta'));
1.1 www 785: } else {
1.2 harris41 786: push @trimlist,$line;
1.1 www 787: }
788: }
1.80 albertel 789: @trimlist = sort {uc($a) cmp uc($b)} (@trimlist);
1.1 www 790: return @trimlist;
791: }
792:
1.17 harris41 793: # ------------------------------- displays one line in appropriate table format
1.23 harris41 794: sub display_line {
1.16 harris41 795: my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
1.53 albertel 796: my (@pathfn, $fndir);
1.97 www 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;
1.107 albertel 801: if ($line=~m|^/res/| && $startdir ne '') {
1.97 www 802: $absolute=1;
803: $pathprefix='';
804: } else {
805: $absolute=0;
806: $pathprefix=$startdir;
807: }
1.1 www 808: my $dirptr=16384;
809: my $fileclr="#ffffe6";
1.45 ng 810: my $iconpath= $r->dir_config('lonIconsURL') . '/';
1.1 www 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;
1.77 www 816: my $msg = &mt('View').' '.$filecom[0].' '.&mt('resources');
817: $msg = &mt('Close').' '.$filecom[0].' '.&mt('directory') if $diropen eq 'opened';
1.1 www 818:
1.45 ng 819: my $tabtag='</td>';
1.1 www 820: my $i=0;
1.109 taceyjo1 821: while ($i<=11) {
1.45 ng 822: $tabtag=join('',$tabtag,"<td> </td>")
1.17 harris41 823: if $hash{'display_attrs_'.$i} == 1;
1.1 www 824: $i++;
825: }
1.63 ng 826: my $valign = ($hash{'display_attrs_7'} == 1 ? 'top' : 'bottom');
1.17 harris41 827:
828: # display uplink arrow
1.45 ng 829: if ($filecom[1] eq 'viewOneUp') {
1.98 www 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:
1.70 ng 835: $r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
836: $r->print("<td>\n");
1.98 www 837: $r->print ('<form method="post" name="dirpathUP" action="'.$updir.
1.16 harris41 838: '/" '.
1.17 harris41 839: 'onSubmit="return rep_dirpath(\'UP\','.
840: 'document.forms.fileattr.acts.value)" '.
1.16 harris41 841: 'enctype="application/x-www-form-urlencoded"'.
842: '>'."\n");
1.17 harris41 843: $r->print ('<input type=hidden name=openuri value="'.
844: $startdir.'">'."\n");
1.16 harris41 845: $r->print ('<input type="hidden" name="acts" value="">'."\n");
1.13 ng 846: $r->print ('<input src="'.$iconpath.'arrow_up.gif"');
1.17 harris41 847: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
848: "\n");
1.77 www 849: $r->print(&mt("Up")." $tabtag</tr></form>\n");
1.13 ng 850: return OK;
851: }
1.97 www 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
1.112 www 857: if ($absolute) { $fileclr='#ccdd99'; }
1.17 harris41 858:
859: # display domain
1.45 ng 860: if ($filecom[1] eq 'domain') {
1.88 www 861: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
862: if ($ENV{'form.dirPointer'} eq "on");
1.70 ng 863: $r->print("<tr valign='$valign' bgcolor=$fileclr>$extrafield");
864: $r->print("<td>");
1.73 albertel 865: &begin_form ($r,$filecom[0]);
866: my $anchor = $filecom[0];
1.3 harris41 867: $anchor =~ s/\///g;
1.13 ng 868: $r->print ('<a name="'.$anchor.'">');
1.16 harris41 869: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 870: $r->print ('<input src="'.$iconpath.'folder_pointer_'.
871: $diropen.'.gif"');
872: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
873: "\n");
1.125 ! foxr 874: my $quotable_filecom = &javascript_escape($filecom[0]);
! 875: $r->print ('<a href="javascript:gothere(\''.$quotable_filecom.
1.73 albertel 876: '\')"><img src="'.$iconpath.'server.gif"');
1.17 harris41 877: $r->print (' border="0" /></a>'."\n");
1.77 www 878: $r->print (&mt("Domain")." - $listname ");
1.60 albertel 879: if ($Apache::lonnet::domaindescription{$listname}) {
880: $r->print("(".$Apache::lonnet::domaindescription{$listname}.
881: ")");
882: }
883: $r->print (" $tabtag</tr></form>\n");
1.1 www 884: return OK;
1.17 harris41 885:
886: # display user directory
1.1 www 887: }
1.45 ng 888: if ($filecom[1] eq 'user') {
1.70 ng 889: $r->print("<tr valign=$valign bgcolor=$fileclr>$extrafield");
890: $r->print("<td nowrap>\n");
1.2 harris41 891: my $curdir = $startdir.$filecom[0].'/';
1.3 harris41 892: my $anchor = $curdir;
893: $anchor =~ s/\///g;
1.13 ng 894: &begin_form ($r,$curdir);
1.17 harris41 895: $r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
896: 'whitespace1.gif" border="0" />'."\n");
1.16 harris41 897: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 898: $r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
899: '.gif"');
900: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
901: "\n");
1.125 ! foxr 902: my $quotable_curdir = &javascript_escape($curdir);
! 903: $r->print ('<a href="javascript:gothere(\''.$quotable_curdir
! 904: .'\')"><img src='.
1.17 harris41 905: $iconpath.'quill.gif border="0" name="'.$msg.
906: '" height="22" /></a>');
1.60 albertel 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");
1.1 www 912: return OK;
913: }
1.17 harris41 914:
1.1 www 915: # display file
1.97 www 916: if (($fnptr == 0 and $filecom[3] ne '') or $absolute) {
917: my $filelink = $pathprefix.$filecom[0];
1.1 www 918: my @file_ext = split (/\./,$listname);
1.25 matthew 919: my $curfext = $file_ext[-1];
1.40 matthew 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: }
1.25 matthew 928: # Set the icon for the file
1.84 albertel 929: my $iconname = &Apache::loncommon::icon($listname);
1.114 www 930: $r->print("<tr valign='$valign' bgcolor=$fileclr><td nowrap='1' align='top'>");
1.104 albertel 931:
1.7 harris41 932: if ($ENV{'form.catalogmode'} eq 'interactive') {
1.125 ! foxr 933: my $quotable_filelink = &javascript_escape($filelink);
1.35 matthew 934: $r->print("<a href=\"javascript:select_data(\'",
1.125 ! foxr 935: $quotable_filelink,"')\">");
1.17 harris41 936: $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
937: "\n");
1.70 ng 938: $r->print("</td><td nowrap>");
1.95 www 939: } elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
1.8 harris41 940: $r->print("<form name='form$fnum'>\n");
941: $r->print("<input type='checkbox' name='filelink"."' ".
1.16 harris41 942: "value='$filelink' onClick='".
943: "javascript:queue(\"form$fnum\")' ");
944: if ($hash{'store_'.$filelink}) {
945: $r->print("checked");
946: }
947: $r->print(">\n");
1.8 harris41 948: $r->print("</form>\n");
1.70 ng 949: $r->print("</td><td nowrap>");
1.16 harris41 950: $hash{"pre_${fnum}_link"}=$filelink;
1.8 harris41 951: $fnum++;
1.7 harris41 952: }
1.95 www 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
1.12 ng 962: if ($indent > 0 and $indent < 11) {
1.17 harris41 963: $r->print("<img src=",$iconpath,"whitespace",$indent,
964: ".gif border='0' />\n");
1.11 ng 965: } elsif ($indent >0) {
1.4 harris41 966: my $ten = int($indent/10.);
967: my $rem = $indent%10.0;
968: my $count = 0;
969: while ($count < $ten) {
1.17 harris41 970: $r->print("<img src=",$iconpath,
971: "whitespace10.gif border='0' />\n");
1.1 www 972: $count++;
1.4 harris41 973: }
1.17 harris41 974: $r->print("<img src=",$iconpath,"whitespace",$rem,
975: ".gif border='0' />\n") if $rem > 0;
1.1 www 976: }
1.95 www 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
1.84 albertel 989: $r->print("<img src='$iconname' border='0' />\n");
1.95 www 990: # Close form to open/close sequence
991: if ($filelink=~/\.(page|sequence)$/) {
992: $r->print('</form>');
993: }
1.125 ! foxr 994: my $quotable_filelink = &javascript_escape($filelink);
! 995:
! 996:
! 997: $r->print (" <a href=\"javascript:openWindow('".$quotable_filelink.
1.69 www 998: "', 'previewfile', '450', '500', 'no', 'yes','yes')\";".
1.17 harris41 999: " TARGET=_self>$listname</a> ");
1000:
1.125 ! foxr 1001: $r->print (" (<a href=\"javascript:openWindow('".$quotable_filelink.
1.71 ng 1002: ".meta', 'metadatafile', '500', '550', 'no', 'yes','no')\"; ".
1.104 albertel 1003: "TARGET=_self>metadata</a>) ");
1.7 harris41 1004: $r->print("</td>\n");
1.45 ng 1005: if ($hash{'display_attrs_0'} == 1) {
1.104 albertel 1006: my $title = &Apache::lonnet::gettitle($filelink,'title');
1.70 ng 1007: $r->print('<td> '.($title eq '' ? ' ' : $title).
1.45 ng 1008: ' </td>'."\n");
1009: }
1.70 ng 1010: $r->print('<td align=right> ',
1.17 harris41 1011: $filecom[8]," </td>\n")
1.45 ng 1012: if $hash{'display_attrs_1'} == 1;
1.70 ng 1013: $r->print('<td> '.
1.17 harris41 1014: (localtime($filecom[9]))." </td>\n")
1.45 ng 1015: if $hash{'display_attrs_2'} == 1;
1.70 ng 1016: $r->print('<td> '.
1.17 harris41 1017: (localtime($filecom[10]))." </td>\n")
1.45 ng 1018: if $hash{'display_attrs_3'} == 1;
1.2 harris41 1019:
1.45 ng 1020: if ($hash{'display_attrs_4'} == 1) {
1.104 albertel 1021: my $author = &Apache::lonnet::metadata($filelink,'author');
1.70 ng 1022: $r->print('<td> '.($author eq '' ? ' ' : $author).
1.17 harris41 1023: " </td>\n");
1.2 harris41 1024: }
1.45 ng 1025: if ($hash{'display_attrs_5'} == 1) {
1.104 albertel 1026: my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
1.45 ng 1027: # $keywords = ' ' if (!$keywords);
1.70 ng 1028: $r->print('<td> '.($keywords eq '' ? ' ' : $keywords).
1.17 harris41 1029: " </td>\n");
1.2 harris41 1030: }
1.109 taceyjo1 1031: #'
1032:
1.45 ng 1033: if ($hash{'display_attrs_6'} == 1) {
1.104 albertel 1034: my $lang = &Apache::lonnet::metadata($filelink,'language');
1.28 harris41 1035: $lang = &Apache::loncommon::languagedescription($lang);
1.70 ng 1036: $r->print('<td> '.($lang eq '' ? ' ' : $lang).
1.17 harris41 1037: " </td>\n");
1.2 harris41 1038: }
1.70 ng 1039: if ($hash{'display_attrs_8'} == 1) {
1.111 www 1040: # statistics
1.117 www 1041: &dynmetaread($filelink);
1.112 www 1042: $r->print("<td>");
1.114 www 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');
1.112 www 1054: $r->print(" </td>\n");
1.111 www 1055:
1.70 ng 1056: }
1.109 taceyjo1 1057: if ($hash{'display_attrs_10'} == 1) {
1058: my $source = &Apache::lonnet::metadata($filelink,'sourceavail');
1.110 albertel 1059: if($source eq 'open') {
1.119 taceyjo1 1060: my $sourcelink = &Apache::lonsource::make_link($filelink,$listname);
1.125 ! foxr 1061: my $quotable_sourcelink = &javascript_escape($sourcelink);
! 1062: $r->print('<td>'."<a href=\"javascript:openWindow('"
! 1063: .$quotable_sourcelink.
1.110 albertel 1064: "', 'previewsource', '700', '700', 'no', 'yes','yes')\";".
1065: " TARGET=_self>Yes</a> "."</td>\n");
1066: } else { #A cuddled else. :P
1.111 www 1067: $r->print("<td> </td>\n");
1.110 albertel 1068: }
1.109 taceyjo1 1069: }
1.111 www 1070: if ($hash{'display_attrs_11'} == 1) {
1071: # links
1.117 www 1072: &dynmetaread($filelink);
1.113 www 1073: $r->print('<td>');
1074: &dynmetaprint($r,$filelink,'goto_list');
1075: &dynmetaprint($r,$filelink,'comefrom_list');
1076: &dynmetaprint($r,$filelink,'sequsage_list');
1.114 www 1077: &dynmetaprint($r,$filelink,'dependencies');
1.113 www 1078: $r->print('</td>');
1.114 www 1079: }
1.115 www 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: }
1.1 www 1109: $r->print("</tr>\n");
1110: }
1.17 harris41 1111:
1.2 harris41 1112: # -- display directory
1.1 www 1113: if ($fnptr == $dirptr) {
1.2 harris41 1114: my $curdir = $startdir.$filecom[0].'/';
1.3 harris41 1115: my $anchor = $curdir;
1116: $anchor =~ s/\///g;
1.63 ng 1117: $r->print("<tr bgcolor=$fileclr>$extrafield<td valign=$valign>");
1.2 harris41 1118: &begin_form ($r,$curdir);
1.4 harris41 1119: my $indentm1 = $indent-1;
1.11 ng 1120: if ($indentm1 < 11 and $indentm1 > 0) {
1.17 harris41 1121: $r->print("<img src=",$iconpath,"whitespace",$indentm1,
1122: ".gif border='0' />\n");
1.4 harris41 1123: } else {
1124: my $ten = int($indentm1/10.);
1125: my $rem = $indentm1%10.0;
1126: my $count = 0;
1127: while ($count < $ten) {
1.17 harris41 1128: $r->print ("<img src=",$iconpath
1129: ,"whitespace10.gif border='0' />\n");
1.12 ng 1130: $count++;
1.4 harris41 1131: }
1.17 harris41 1132: $r->print ("<img src=",$iconpath,"whitespace",$rem,
1133: ".gif border='0' />\n") if $rem > 0;
1.1 www 1134: }
1.16 harris41 1135: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 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");
1.125 ! foxr 1140: my $quotable_curdir = &javascript_escape($curdir);
! 1141: $r->print ('<a href="javascript:gothere(\''
! 1142: .$quotable_curdir.'\')"><img src="'.
1.17 harris41 1143: $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
1144: "\n");
1.86 www 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: }
1.115 www 1184: if ($hash{'display_attrs_10'} == 1) {
1.109 taceyjo1 1185: $r->print('<td> </td>');
1186: }
1.111 www 1187: if ($hash{'display_attrs_11'} == 1) {
1188: $r->print('<td> </td>');
1189: }
1.115 www 1190: if ($hash{'display_attrs_7'} == 1) {
1191: $r->print('<td> </td>');
1192: }
1.86 www 1193: $r->print('</form></tr>');
1.1 www 1194: }
1.2 harris41 1195:
1.1 www 1196: }
1197:
1.113 www 1198: sub dynmetaprint {
1199: my ($r,$filelink,$item)=@_;
1200: if ($dynhash{$filelink}->{$item}) {
1.114 www 1201: $r->print("\n<br />".$fieldnames{$item}.': '.
1.113 www 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:
1.14 harris41 1210: # ------------------- prints the beginning of a form for directory or file link
1.1 www 1211: sub begin_form {
1212: my ($r,$uri) = @_;
1.3 harris41 1213: my $anchor = $uri;
1214: $anchor =~ s/\///g;
1.17 harris41 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)" '.
1.16 harris41 1219: 'enctype="application/x-www-form-urlencoded">'."\n");
1.17 harris41 1220: $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
1221: "\n");
1.88 www 1222: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
1.16 harris41 1223: $dnum++;
1.17 harris41 1224: }
1225:
1226: # --------- settings whenever the user causes the indexer window to be launched
1227: sub start_fresh_session {
1.48 matthew 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'};
1.27 harris41 1234: foreach (keys %hash) {
1.48 matthew 1235: delete $hash{$_} if (/^(pre_|store)/);
1.27 harris41 1236: }
1.1 www 1237: }
1238:
1.35 matthew 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:
1.1 www 1252: 1;
1.54 www 1253:
1254: sub cleanup {
1.55 www 1255: if (tied(%hash)){
1256: &Apache::lonnet::logthis('Cleanup indexer: hash');
1257: }
1.54 www 1258: }
1.23 harris41 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>