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