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