Annotation of loncom/interface/lonindexer.pm, revision 1.130
1.1 www 1: # The LearningOnline Network with CAPA
1.24 harris41 2: # Directory Indexer
3: #
1.130 ! albertel 4: # $Id: lonindexer.pm,v 1.129 2005/02/17 08:29:42 albertel Exp $
1.24 harris41 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
1.14 harris41 14: #
1.24 harris41 15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
1.14 harris41 27: #
1.23 harris41 28: ###
29:
30: ###############################################################################
31: ## ##
32: ## ORGANIZATION OF THIS PERL MODULE ##
33: ## ##
34: ## 1. Description of functions ##
35: ## 2. Modules used by this module ##
36: ## 3. Choices for different output views (detailed, summary, xml, etc) ##
37: ## 4. BEGIN block (to be run once after compilation) ##
38: ## 5. Handling routine called via Apache and mod_perl ##
39: ## 6. Other subroutines ##
40: ## ##
41: ###############################################################################
1.7 harris41 42:
1.1 www 43: package Apache::lonindexer;
44:
1.23 harris41 45: # ------------------------------------------------- modules used by this module
1.1 www 46: use strict;
47: use Apache::lonnet();
1.30 harris41 48: use Apache::loncommon();
1.83 www 49: use Apache::lonhtmlcommon();
1.94 www 50: use Apache::lonsequence();
1.1 www 51: use Apache::Constants qw(:common);
1.70 ng 52: use Apache::lonmeta;
1.2 harris41 53: use Apache::File;
1.77 www 54: use Apache::lonlocal;
1.109 taceyjo1 55: use Apache::lonsource();
1.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.66 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.15 harris41 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.
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.118 albertel 141: if (defined($ENV{'form.titleelement'}) &&
142: $ENV{'form.titleelement'} ne '') {
1.108 albertel 143: my $verify_title = &Apache::lonnet::gettitle($ENV{'form.acts'});
1.113 www 144: # &Apache::lonnet::logthis("Hrrm $ENV{'form.acts'} -- $verify_title");
1.108 albertel 145: $verify_title=~s/'/\\'/g;
146: $extra='window.opener.document.forms["'.$ENV{'form.form'}.'"].elements["'.$ENV{'form.titleelement'}.'"].value=\''.$verify_title.'\';';
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.125 foxr 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.48 matthew 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.15 harris41 174: if ($ENV{'form.catalogmode'} eq 'interactive') {
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.77 www 181: <input type="button" name="close" value='$cl' onClick="self.close()">
1.7 harris41 182: END
1.16 harris41 183: }
1.15 harris41 184: elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
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.77 www 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.17 harris41 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.79 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'
216: if (exists $ENV{'form.omit'}) {
217: @Omit = split(',',$ENV{'form.omit'});
218: }
219: if (exists $ENV{'form.only'}) {
220: @Only = split(',',$ENV{'form.only'});
221: }
222:
1.35 matthew 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.79 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='';
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.16 harris41 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.129 albertel 350: my $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.16 harris41 382: if ($ENV{'form.catalogmode'} eq 'groupimport') {
383: my $acts=$ENV{'form.acts'};
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.87 www 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};
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.87 www 491: (($ENV{'form.catalogmode'} eq 'groupimport')?
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
496: my $reshome=$ENV{'course.'.$ENV{'request.course.id'}.'.reshome'};
497: if ($reshome) {
498: $r->print("<font size='+2'><a href='");
499: if ($ENV{'form.catalogmode'} eq 'groupimport') {
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.2 harris41 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.88 www 572: if ($ENV{'form.dirPointer'} ne 'on') {
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'>");
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.87 www 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="'.
827: $startdir.'">'."\n");
1.16 harris41 828: $r->print ('<input type="hidden" name="acts" value="">'."\n");
1.13 ng 829: $r->print ('<input src="'.$iconpath.'arrow_up.gif"');
1.17 harris41 830: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
831: "\n");
1.77 www 832: $r->print(&mt("Up")." $tabtag</tr></form>\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.88 www 844: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
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.16 harris41 852: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 853: $r->print ('<input src="'.$iconpath.'folder_pointer_'.
854: $diropen.'.gif"');
855: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
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: }
866: $r->print (" $tabtag</tr></form>\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.16 harris41 880: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 881: $r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
882: '.gif"');
883: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
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) "); }
894: $r->print ($tabtag.'</tr></form>'."\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.114 www 913: $r->print("<tr valign='$valign' bgcolor=$fileclr><td nowrap='1' align='top'>");
1.104 albertel 914:
1.7 harris41 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.95 www 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: }
930: $r->print(">\n");
1.8 harris41 931: $r->print("</form>\n");
1.70 ng 932: $r->print("</td><td nowrap>");
1.16 harris41 933: $hash{"pre_${fnum}_link"}=$filelink;
1.8 harris41 934: $fnum++;
1.7 harris41 935: }
1.95 www 936: # Form to open or close sequences
937: if ($filelink=~/\.(page|sequence)$/) {
938: my $curdir = $startdir.$filecom[0].'/';
939: my $anchor = $curdir;
940: $anchor =~ s/\///g;
941: &begin_form($r,$curdir);
942: $indent--;
943: }
944: # General indentation
1.12 ng 945: if ($indent > 0 and $indent < 11) {
1.17 harris41 946: $r->print("<img src=",$iconpath,"whitespace",$indent,
947: ".gif border='0' />\n");
1.11 ng 948: } elsif ($indent >0) {
1.4 harris41 949: my $ten = int($indent/10.);
950: my $rem = $indent%10.0;
951: my $count = 0;
952: while ($count < $ten) {
1.17 harris41 953: $r->print("<img src=",$iconpath,
954: "whitespace10.gif border='0' />\n");
1.1 www 955: $count++;
1.4 harris41 956: }
1.17 harris41 957: $r->print("<img src=",$iconpath,"whitespace",$rem,
958: ".gif border='0' />\n") if $rem > 0;
1.1 www 959: }
1.95 www 960: # Sequence open/close icon
961: if ($filelink=~/\.(page|sequence)$/) {
962: my $curdir = $startdir.$filecom[0].'/';
963: my $anchor = $curdir;
964: $anchor =~ s/\///g;
965: $r->print ('<input type="hidden" name="acts" value="">');
966: $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
967: 'folder_pointer_'.$diropen.'.gif"');
968: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
969: "\n");
970: }
971: # Filetype icons
1.84 albertel 972: $r->print("<img src='$iconname' border='0' />\n");
1.95 www 973: # Close form to open/close sequence
974: if ($filelink=~/\.(page|sequence)$/) {
975: $r->print('</form>');
976: }
1.128 foxr 977: my $quotable_filelink = &Apache::loncommon::escape_single($filelink);
1.125 foxr 978:
979:
980: $r->print (" <a href=\"javascript:openWindow('".$quotable_filelink.
1.69 www 981: "', 'previewfile', '450', '500', 'no', 'yes','yes')\";".
1.17 harris41 982: " TARGET=_self>$listname</a> ");
983:
1.125 foxr 984: $r->print (" (<a href=\"javascript:openWindow('".$quotable_filelink.
1.71 ng 985: ".meta', 'metadatafile', '500', '550', 'no', 'yes','no')\"; ".
1.104 albertel 986: "TARGET=_self>metadata</a>) ");
1.7 harris41 987: $r->print("</td>\n");
1.45 ng 988: if ($hash{'display_attrs_0'} == 1) {
1.104 albertel 989: my $title = &Apache::lonnet::gettitle($filelink,'title');
1.70 ng 990: $r->print('<td> '.($title eq '' ? ' ' : $title).
1.45 ng 991: ' </td>'."\n");
992: }
1.70 ng 993: $r->print('<td align=right> ',
1.17 harris41 994: $filecom[8]," </td>\n")
1.45 ng 995: if $hash{'display_attrs_1'} == 1;
1.70 ng 996: $r->print('<td> '.
1.17 harris41 997: (localtime($filecom[9]))." </td>\n")
1.45 ng 998: if $hash{'display_attrs_2'} == 1;
1.70 ng 999: $r->print('<td> '.
1.17 harris41 1000: (localtime($filecom[10]))." </td>\n")
1.45 ng 1001: if $hash{'display_attrs_3'} == 1;
1.2 harris41 1002:
1.45 ng 1003: if ($hash{'display_attrs_4'} == 1) {
1.104 albertel 1004: my $author = &Apache::lonnet::metadata($filelink,'author');
1.70 ng 1005: $r->print('<td> '.($author eq '' ? ' ' : $author).
1.17 harris41 1006: " </td>\n");
1.2 harris41 1007: }
1.45 ng 1008: if ($hash{'display_attrs_5'} == 1) {
1.104 albertel 1009: my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
1.45 ng 1010: # $keywords = ' ' if (!$keywords);
1.70 ng 1011: $r->print('<td> '.($keywords eq '' ? ' ' : $keywords).
1.17 harris41 1012: " </td>\n");
1.2 harris41 1013: }
1.109 taceyjo1 1014: #'
1015:
1.45 ng 1016: if ($hash{'display_attrs_6'} == 1) {
1.104 albertel 1017: my $lang = &Apache::lonnet::metadata($filelink,'language');
1.28 harris41 1018: $lang = &Apache::loncommon::languagedescription($lang);
1.70 ng 1019: $r->print('<td> '.($lang eq '' ? ' ' : $lang).
1.17 harris41 1020: " </td>\n");
1.2 harris41 1021: }
1.70 ng 1022: if ($hash{'display_attrs_8'} == 1) {
1.111 www 1023: # statistics
1.117 www 1024: &dynmetaread($filelink);
1.112 www 1025: $r->print("<td>");
1.114 www 1026: &dynmetaprint($r,$filelink,'count');
1027: &dynmetaprint($r,$filelink,'course');
1028: &dynmetaprint($r,$filelink,'stdno');
1029: &dynmetaprint($r,$filelink,'avetries');
1030: &dynmetaprint($r,$filelink,'difficulty');
1031: &dynmetaprint($r,$filelink,'disc');
1032: &dynmetaprint($r,$filelink,'clear');
1033: &dynmetaprint($r,$filelink,'technical');
1034: &dynmetaprint($r,$filelink,'correct');
1035: &dynmetaprint($r,$filelink,'helpful');
1036: &dynmetaprint($r,$filelink,'depth');
1.112 www 1037: $r->print(" </td>\n");
1.111 www 1038:
1.70 ng 1039: }
1.109 taceyjo1 1040: if ($hash{'display_attrs_10'} == 1) {
1041: my $source = &Apache::lonnet::metadata($filelink,'sourceavail');
1.110 albertel 1042: if($source eq 'open') {
1.119 taceyjo1 1043: my $sourcelink = &Apache::lonsource::make_link($filelink,$listname);
1.128 foxr 1044: my $quotable_sourcelink = &Apache::loncommon::escape_single($sourcelink);
1.125 foxr 1045: $r->print('<td>'."<a href=\"javascript:openWindow('"
1046: .$quotable_sourcelink.
1.110 albertel 1047: "', 'previewsource', '700', '700', 'no', 'yes','yes')\";".
1048: " TARGET=_self>Yes</a> "."</td>\n");
1049: } else { #A cuddled else. :P
1.111 www 1050: $r->print("<td> </td>\n");
1.110 albertel 1051: }
1.109 taceyjo1 1052: }
1.111 www 1053: if ($hash{'display_attrs_11'} == 1) {
1054: # links
1.117 www 1055: &dynmetaread($filelink);
1.113 www 1056: $r->print('<td>');
1057: &dynmetaprint($r,$filelink,'goto_list');
1058: &dynmetaprint($r,$filelink,'comefrom_list');
1059: &dynmetaprint($r,$filelink,'sequsage_list');
1.114 www 1060: &dynmetaprint($r,$filelink,'dependencies');
1.113 www 1061: $r->print('</td>');
1.114 www 1062: }
1.115 www 1063: if ($hash{'display_attrs_7'} == 1) {
1064: # Show resource
1065: my $output='';
1066: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
1067: if ($embstyle eq 'ssi') {
1068: my $cache=$Apache::lonnet::perlvar{'lonDocRoot'}.$filelink.
1069: '.tmp';
1070: if ((!$ENV{'form.updatedisplay'}) &&
1071: (-e $cache)) {
1072: open(FH,$cache);
1073: $output=join("\n",<FH>);
1074: close(FH);
1075: } else {
1076: $output=&Apache::lonnet::ssi_body($filelink);
1077: open(FH,">$cache");
1078: print FH $output;
1079: close(FH);
1080: }
1081: $output='<font size="-2">'.$output.'</font>';
1082: } elsif ($embstyle eq 'img') {
1083: $output='<img src="'.$filelink.'" />';
1084: } elsif ($filelink=~/^\/res\/(\w+)\/(\w+)\//) {
1085: $output='<img src="http://'.
1086: $Apache::lonnet::hostname{&Apache::lonnet::homeserver($2,$1)}.
1087: '/cgi-bin/thumbnail.gif?url='.$filelink.'" />';
1088: }
1089: $r->print('<td> '.($output eq '' ? ' ':$output).
1090: " </td>\n");
1091: }
1.1 www 1092: $r->print("</tr>\n");
1093: }
1.17 harris41 1094:
1.2 harris41 1095: # -- display directory
1.1 www 1096: if ($fnptr == $dirptr) {
1.2 harris41 1097: my $curdir = $startdir.$filecom[0].'/';
1.3 harris41 1098: my $anchor = $curdir;
1099: $anchor =~ s/\///g;
1.63 ng 1100: $r->print("<tr bgcolor=$fileclr>$extrafield<td valign=$valign>");
1.2 harris41 1101: &begin_form ($r,$curdir);
1.4 harris41 1102: my $indentm1 = $indent-1;
1.11 ng 1103: if ($indentm1 < 11 and $indentm1 > 0) {
1.17 harris41 1104: $r->print("<img src=",$iconpath,"whitespace",$indentm1,
1105: ".gif border='0' />\n");
1.4 harris41 1106: } else {
1107: my $ten = int($indentm1/10.);
1108: my $rem = $indentm1%10.0;
1109: my $count = 0;
1110: while ($count < $ten) {
1.17 harris41 1111: $r->print ("<img src=",$iconpath
1112: ,"whitespace10.gif border='0' />\n");
1.12 ng 1113: $count++;
1.4 harris41 1114: }
1.17 harris41 1115: $r->print ("<img src=",$iconpath,"whitespace",$rem,
1116: ".gif border='0' />\n") if $rem > 0;
1.1 www 1117: }
1.16 harris41 1118: $r->print ('<input type="hidden" name="acts" value="">');
1.17 harris41 1119: $r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
1120: 'folder_pointer_'.$diropen.'.gif"');
1121: $r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
1122: "\n");
1.128 foxr 1123: my $quotable_curdir = &Apache::loncommon::escape_single($curdir);
1.125 foxr 1124: $r->print ('<a href="javascript:gothere(\''
1125: .$quotable_curdir.'\')"><img src="'.
1.17 harris41 1126: $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
1127: "\n");
1.86 www 1128: $r->print ("$listname</td>\n");
1129: # Attributes
1130: my $filelink = $startdir.$filecom[0].'/default';
1131:
1132: if ($hash{'display_attrs_0'} == 1) {
1133: my $title = &Apache::lonnet::gettitle($filelink,'title');
1134: $r->print('<td> '.($title eq '' ? ' ' : $title).
1135: ' </td>'."\n");
1136: }
1137: $r->print('<td align=right> ',
1138: $filecom[8]," </td>\n")
1139: if $hash{'display_attrs_1'} == 1;
1140: $r->print('<td> '.
1141: (localtime($filecom[9]))." </td>\n")
1142: if $hash{'display_attrs_2'} == 1;
1143: $r->print('<td> '.
1144: (localtime($filecom[10]))." </td>\n")
1145: if $hash{'display_attrs_3'} == 1;
1146:
1147: if ($hash{'display_attrs_4'} == 1) {
1148: my $author = &Apache::lonnet::metadata($filelink,'author');
1149: $r->print('<td> '.($author eq '' ? ' ' : $author).
1150: " </td>\n");
1151: }
1152: if ($hash{'display_attrs_5'} == 1) {
1153: my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
1154: # $keywords = ' ' if (!$keywords);
1155: $r->print('<td> '.($keywords eq '' ? ' ' : $keywords).
1156: " </td>\n");
1157: }
1158: if ($hash{'display_attrs_6'} == 1) {
1159: my $lang = &Apache::lonnet::metadata($filelink,'language');
1160: $lang = &Apache::loncommon::languagedescription($lang);
1161: $r->print('<td> '.($lang eq '' ? ' ' : $lang).
1162: " </td>\n");
1163: }
1164: if ($hash{'display_attrs_8'} == 1) {
1165: $r->print('<td> </td>');
1166: }
1.115 www 1167: if ($hash{'display_attrs_10'} == 1) {
1.109 taceyjo1 1168: $r->print('<td> </td>');
1169: }
1.111 www 1170: if ($hash{'display_attrs_11'} == 1) {
1171: $r->print('<td> </td>');
1172: }
1.115 www 1173: if ($hash{'display_attrs_7'} == 1) {
1174: $r->print('<td> </td>');
1175: }
1.86 www 1176: $r->print('</form></tr>');
1.1 www 1177: }
1.2 harris41 1178:
1.1 www 1179: }
1180:
1.113 www 1181: sub dynmetaprint {
1182: my ($r,$filelink,$item)=@_;
1183: if ($dynhash{$filelink}->{$item}) {
1.114 www 1184: $r->print("\n<br />".$fieldnames{$item}.': '.
1.113 www 1185: &Apache::lonmeta::prettyprint($item,
1186: $dynhash{$filelink}->{$item},
1187: (($ENV{'form.catalogmode'} ne 'groupimport')?'preview':''),
1188: '',
1189: (($ENV{'form.catalogmode'} eq 'groupimport')?'document.forms.fileattr':''),1));
1190: }
1191: }
1192:
1.14 harris41 1193: # ------------------- prints the beginning of a form for directory or file link
1.1 www 1194: sub begin_form {
1195: my ($r,$uri) = @_;
1.3 harris41 1196: my $anchor = $uri;
1197: $anchor =~ s/\///g;
1.17 harris41 1198: $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
1199: '#'.$anchor.
1200: '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
1201: ',document.forms.fileattr.acts.value)" '.
1.16 harris41 1202: 'enctype="application/x-www-form-urlencoded">'."\n");
1.17 harris41 1203: $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
1204: "\n");
1.88 www 1205: $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
1.16 harris41 1206: $dnum++;
1.17 harris41 1207: }
1208:
1209: # --------- settings whenever the user causes the indexer window to be launched
1210: sub start_fresh_session {
1.48 matthew 1211: delete $hash{'form.catalogmode'};
1212: delete $hash{'form.mode'};
1213: delete $hash{'form.form'};
1214: delete $hash{'form.element'};
1215: delete $hash{'form.omit'};
1216: delete $hash{'form.only'};
1.27 harris41 1217: foreach (keys %hash) {
1.48 matthew 1218: delete $hash{$_} if (/^(pre_|store)/);
1.27 harris41 1219: }
1.1 www 1220: }
1221:
1.35 matthew 1222: # ------------------------------------------------------------------- setvalues
1223: sub setvalues {
1224: # setvalues is used in registerurl to synchronize the database
1225: # hash and environment hashes
1226: my ($H1,$h1key,$H2,$h2key) =@_;
1227: #
1228: if (exists $H2->{$h2key}) {
1229: $H1->{$h1key} = $H2->{$h2key};
1230: } elsif (exists $H1->{$h1key}) {
1231: $H2->{$h2key} = $H1->{$h1key};
1232: }
1233: }
1234:
1.1 www 1235: 1;
1.54 www 1236:
1237: sub cleanup {
1.55 www 1238: if (tied(%hash)){
1239: &Apache::lonnet::logthis('Cleanup indexer: hash');
1240: }
1.54 www 1241: }
1.23 harris41 1242:
1.126 foxr 1243:
1244:
1245:
1246:
1.23 harris41 1247: =head1 NAME
1248:
1249: Apache::lonindexer - mod_perl module for cross server filesystem browsing
1250:
1251: =head1 SYNOPSIS
1252:
1253: Invoked by /etc/httpd/conf/srm.conf:
1254:
1255: <LocationMatch "^/res.*/$">
1256: SetHandler perl-script
1257: PerlHandler Apache::lonindexer
1258: </LocationMatch>
1259:
1260: =head1 INTRODUCTION
1261:
1262: This module enables a scheme of browsing across a cross server.
1263:
1264: This is part of the LearningOnline Network with CAPA project
1265: described at http://www.lon-capa.org.
1266:
1267: =head1 BEGIN SUBROUTINE
1268:
1269: This routine is only run once after compilation.
1270:
1271: =over 4
1272:
1273: =item *
1274:
1275: Initializes %language hash table.
1276:
1277: =back
1278:
1279: =head1 HANDLER SUBROUTINE
1280:
1281: This routine is called by Apache and mod_perl.
1282:
1283: =over 4
1284:
1285: =item *
1286:
1287: read in machine configuration variables
1288:
1289: =item *
1290:
1291: see if called from an interactive mode
1292:
1293: =item *
1294:
1295: refresh environment with user database values (in %hash)
1296:
1297: =item *
1298:
1299: define extra fields and buttons in case of special mode
1300:
1301: =item *
1302:
1303: set catalogmodefunctions to have extra needed javascript functionality
1304:
1305: =item *
1306:
1307: print header
1308:
1309: =item *
1310:
1311: evaluate actions from previous page (both cumulatively and chronologically)
1312:
1313: =item *
1314:
1315: output title
1316:
1317: =item *
1318:
1319: get state of file attributes to be showing
1320:
1321: =item *
1322:
1323: output state of file attributes to be showing
1324:
1325: =item *
1326:
1327: output starting row to the indexed file/directory hierarchy
1328:
1329: =item *
1330:
1331: read in what directories have previously been set to "open"
1332:
1333: =item *
1334:
1335: if not at top level, provide an uplink arrow
1336:
1337: =item *
1338:
1339: recursively go through all the directories and output as appropriate
1340:
1341: =item *
1342:
1343: information useful for group import
1344:
1345: =item *
1346:
1347: end the tables
1348:
1349: =item *
1350:
1351: end the output and return
1352:
1353: =back
1354:
1355: =head1 OTHER SUBROUTINES
1356:
1357: =over 4
1358:
1359: =item *
1360:
1361: scanDir - recursive scan of a directory
1362:
1363: =item *
1364:
1365: get_list - get complete matched list based on the uri (returns an array)
1366:
1367: =item *
1368:
1369: match_ext - filters out files based on extensions (returns an array)
1370:
1371: =item *
1372:
1373: display_line - displays one line in appropriate table format
1374:
1375: =item *
1376:
1377: begin_form - prints the beginning of a form for directory or file link
1378:
1379: =item *
1380:
1381: start_fresh_session - settings whenever the user causes the indexer window
1382: to be launched
1383:
1384: =back
1385:
1386: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>