File:
[LON-CAPA] /
loncom /
interface /
lonindexer.pm
Revision
1.213.4.9:
download - view:
text,
annotated -
select for diffs
Thu Sep 3 15:49:27 2020 UTC (4 years ago) by
raeburn
Branches:
version_2_11_X
CVS tags:
version_2_11_5_msu,
version_2_11_5,
version_2_11_4_uiuc,
version_2_11_4_msu,
version_2_11_4,
version_2_11_3_uiuc,
version_2_11_3_msu,
version_2_11_3
Diff to branchpoint 1.213:
preferred,
unified
- For 2.11
Backport 1.226, 1.230
1: # The LearningOnline Network with CAPA
2: # Directory Indexer
3: #
4: # $Id: lonindexer.pm,v 1.213.4.9 2020/09/03 15:49:27 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: ###
29:
30: ###############################################################################
31: ## ##
32: ## ORGANIZATION OF THIS PERL MODULE ##
33: ## ##
34: ## 1. Description of functions ##
35: ## 2. Modules used by this module ##
36: ## 3. Choices for different output views (detailed, summary, xml, etc) ##
37: ## 4. Handling routine called via Apache and mod_perl ##
38: ## 5. Other subroutines ##
39: ## ##
40: ###############################################################################
41:
42: package Apache::lonindexer;
43:
44: # ------------------------------------------------- modules used by this module
45: use strict;
46: use Apache::lonnet;
47: use Apache::loncommon();
48: use Apache::lonhtmlcommon();
49: use Apache::lonsequence();
50: use Apache::Constants qw(:common);
51: use Apache::lonmeta;
52: use Apache::File;
53: use Apache::lonlocal;
54: use Apache::lonsource();
55: use Apache::groupsort();
56: use GDBM_File;
57: use LONCAPA qw(:match);
58:
59: # ---------------------------------------- variables used throughout the module
60: my %hash; # global user-specific gdbm file
61: my %dirs; # keys are directories, values are the open/close status
62: my %dynhash; # hash of hashes for dynamic metadata
63: my %dynread; # hash of directories already read for dynamic metadata
64: my %fieldnames; # Metadata fieldnames
65: # ----- Values which are set by the handler subroutine and are accessible to
66: # ----- other methods.
67: my $extrafield; # default extra table cell
68: my $fnum; # file counter
69: my $dnum; # directory counter
70:
71: # ----- Used to include or exclude files with certain extensions.
72: my @Only = ();
73: my @Omit = ();
74:
75:
76:
77:
78: # ----------------------------- Handling routine called via Apache and mod_perl
79: sub handler {
80: my $r = shift;
81: my $c = $r->connection();
82: &Apache::loncommon::content_type($r,'text/html');
83: &Apache::loncommon::no_cache($r);
84: $r->send_http_header;
85: return OK if $r->header_only;
86: $fnum=0;
87: $dnum=0;
88:
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);
93: %fieldnames=&Apache::lonmeta::fieldnames();
94:
95: # --------------------------------------------------------------- get icon path
96: my $iconpath= $r->dir_config('lonIconsURL') . "/";
97:
98: #SB my $fileclr='#ffffe6';
99: my $line;
100: my (@attrchk,@openpath,$typeselect);
101: my $uri=$r->uri;
102:
103: # -------------------------------------- see if called from an interactive mode
104: # Get the parameters from the query string
105: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
106: ['catalogmode','launch','acts','mode','form','element',
107: 'only','omit','titleelement']);
108: #-------------------------------------------------------------------
109: my $closebutton='';
110: my $groupimportbutton='';
111: my $colspan='';
112:
113: $extrafield='';
114: my $diropendb = LONCAPA::tempdir() .
115: "$env{'user.domain'}_$env{'user.name'}_sel_res.db";
116: %hash = ();
117: {
118: my %dbfile;
119: if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_WRITER(),0640)) {
120: if ($env{'form.launch'} eq '1') {
121: &start_fresh_session(\%dbfile);
122: }
123: while(my($key,$value)=each(%dbfile)) {
124: $hash{$key}=$value;
125: }
126: untie(%dbfile);
127: }
128: }
129: # - Evaluate actions from previous page (both cumulatively and chronologically)
130: if ($env{'form.catalogmode'} eq 'import' || $hash{'form.catalogmode'} eq 'import') {
131: &Apache::groupsort::update_actions_hash(\%hash);
132: }
133:
134: {
135: #Hijack lonindexer to verify a title and be close down.
136: if ($env{'form.launch'} eq '2') {
137: &Apache::loncommon::content_type($r,'text/html');
138: my $extra='';
139: if (defined($env{'form.titleelement'}) &&
140: $env{'form.titleelement'} ne '') {
141: my $verify_title = &Apache::lonnet::gettitle($env{'form.acts'});
142: # &Apache::lonnet::logthis("Hrrm $env{'form.acts'} -- $verify_title");
143: $verify_title=~s/'/\\'/g;
144: $extra='window.opener.document.forms["'.$env{'form.form'}.'"].elements["'.$env{'form.titleelement'}.'"].value=\''.$verify_title.'\';';
145: }
146: my $js = <<ENDSUBM;
147: <script type="text/javascript">
148: function load() {
149: window.opener.document.forms["$env{'form.form'}"]
150: .elements["$env{'form.element'}"]
151: .value='$env{'form.acts'}';
152: $extra
153: window.close();
154: }
155: </script>
156: ENDSUBM
157: $r->print(&Apache::loncommon::start_page(undef,$js,
158: {'only_body' =>1,
159: 'add_modal' => 1,
160: 'add_wishlist' => 1,
161: 'add_entries' =>
162: {'onload' => "load();"},}
163: ).
164: &Apache::loncommon::end_page());
165: return OK;
166: }
167:
168: # -------------------- refresh environment with user database values (in %hash)
169: &setvalues(\%hash,'form.catalogmode',\%env,'form.catalogmode' );
170:
171: # --------------------- define extra fields and buttons in case of special mode
172: if ($env{'form.catalogmode'} eq 'interactive') {
173: #SB $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
174: $extrafield='<td class="LC_bottom">'.
175: '<img alt="" src="'.$iconpath.'whitespace1.gif"'.
176: ' class="LC_icon" /></td>';
177: $colspan=" colspan='2' ";
178: my $cl=&mt('Close');
179: $closebutton=<<END;
180: <input type="button" name="close" value='$cl' onclick="self.close()" />
181: END
182: }
183: elsif ($env{'form.catalogmode'} eq 'import') {
184: #SB $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
185: $extrafield='<td class="LC_bottom">'.
186: '<img alt="" src="'.$iconpath.'whitespace1.gif"'.
187: ' class="LC_icon" /></td>';
188: $colspan=" colspan='2' ";
189: my $cl=&mt('Close');
190: my $gi=&mt('Import');
191: $closebutton=<<END;
192: <input type="button" name="close" value='$cl' onclick="self.close()" />
193: END
194: $groupimportbutton=<<END;
195: <input type="button" name="groupimport" value='$gi'
196: onclick="javascript:select_group()" />
197: END
198: }
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.
207: #&Apache::lonxml::debug('Checking mode, form, element');
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' );
214:
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:
223: my $mode = $env{'form.mode'};
224: my ($form,$element,$titleelement);
225: if ($mode eq 'edit' || $mode eq 'parmset') {
226: $form = $env{'form.form'};
227: $element = $env{'form.element'};
228: $titleelement = $env{'form.titleelement'};
229: }
230: #&Apache::lonxml::debug("mode=$mode form=$form element=$element titleelement=$titleelement");
231: # ------ set catalogmodefunctions to have extra needed javascript functionality
232: my $catalogmodefunctions='';
233: if ($env{'form.catalogmode'} eq 'interactive' or
234: $env{'form.catalogmode'} eq 'import') {
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.
239:
240: #
241: # There is now also mode "simple", which is for the simple version of the rat
242: #
243: #
244: if (!defined($mode) || ($mode ne 'edit' && $mode ne 'parmset')) {
245: my $location = "/adm/groupsort?&inhibitmenu=yes&catalogmode=import&";
246: $location .= "mode=".$mode."&";
247: $location .= "acts=";
248: $catalogmodefunctions=<<"END";
249: function select_data(url) {
250: changeURL(url);
251: self.close();
252: }
253: function select_group() {
254: window.location="$location"+document.forms.fileattr.acts.value;
255: }
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: }
261: }
262: }
263: END
264: } elsif ($mode eq 'edit') { # we are in 'edit' mode
265: my $location = "/adm/groupsort?catalogmode=interactive&";
266: $location .= "form=$form&element=$element&mode=edit&acts=";
267: $catalogmodefunctions=<<END;
268: // mode = $mode
269: function select_data(url) {
270: var location = "/res/?launch=2&form=$form&element=$element&titleelement=$titleelement&acts=" + url;
271: window.location=location;
272: if (window.opener.document.forms["$form"].elements["$element"].value != url) {
273: window.opener.unClean();
274: }
275: }
276: function select_group() {
277: window.location="$location"+document.forms.fileattr.acts.value;
278: }
279:
280: function changeURL(val) {
281: if (window.opener.document) {
282: window.opener.document.forms["$form"].elements["$element"].value=val;
283: } else {
284: alert("The file you selected is: "+val);
285: }
286: }
287: END
288: if (!$titleelement) {
289: $catalogmodefunctions.='function changeTitle(val) {}';
290: } else {
291: $catalogmodefunctions.=<<END;
292: function changeTitle(val) {
293: if (window.opener.document) {
294: window.opener.document.forms["$form"].elements["$titleelement"].value=val;
295: } else {
296: alert("The title of the file you selected is: "+val);
297: }
298: }
299: END
300: }
301: } elsif ($mode eq 'parmset') {
302: my $location = "/adm/groupsort?catalogmode=interactive&";
303: $location .= "form=$form&element=$element&mode=parmset&acts=";
304: $catalogmodefunctions=<<END;
305: // mode = $mode
306: function select_data(url) {
307: changeURL(url);
308: self.close();
309: }
310:
311: function select_group() {
312: window.location="$location"+document.forms.fileattr.acts.value;
313: }
314:
315: function changeURL(val) {
316: if (window.opener.document) {
317: var elementname = "$element";
318: window.opener.document.forms["$form"].elements[elementname].value=val;
319: } else {
320: alert("The file you selected is: "+val);
321: }
322: }
323:
324: END
325: }
326: }
327: $catalogmodefunctions.=<<END;
328: var acts='';
329: function rep_dirpath(suffix,val) {
330: eval("document.forms.dirpath"+suffix+".acts.value=val");
331: }
332: END
333: if ($env{'form.catalogmode'} eq 'import') {
334: $catalogmodefunctions.=<<END;
335: function queue(val) {
336: if (eval("document.forms."+val+".filelink.checked")) {
337: var l=val.length;
338: var v=val.substring(4,l);
339: document.forms.fileattr.acts.value+='1a'+v+'b';
340: }
341: else {
342: var l=val.length;
343: var v=val.substring(4,l);
344: document.forms.fileattr.acts.value+='0a'+v+'b';
345: }
346: }
347: END
348: }
349:
350: my $inhibit_menu = "+'&".&Apache::loncommon::inhibit_menu_check()."'";
351: # ---------------------------------------------------------------- Print Header
352:
353: my $js = <<"ENDHEADER";
354: <script type="text/javascript">
355: // <![CDATA[
356: $catalogmodefunctions;
357: function update_only(field) {
358: alert(field.name);
359: }
360: function checkAll() {
361: var numForms = document.forms.length;
362: for (i=0;i<numForms;i++) {
363: var numElements = document.forms[i].elements.length;
364: for (j=0;j<numElements;j++){
365: var fieldName = document.forms[i].elements[j].name;
366: if (fieldName == 'filelink') {
367: document.forms[i].elements[j].checked = true;
368: queue(document.forms[i].name);
369: }
370: }
371: }
372: }
373: function uncheckAll() {
374: var numForms = document.forms.length;
375: for (i=0;i<numForms;i++) {
376: var numElements = document.forms[i].elements.length;
377: for (j=0;j<numElements;j++){
378: var fieldName = document.forms[i].elements[j].name;
379: if (fieldName == 'filelink') {
380: document.forms[i].elements[j].checked = false;
381: queue(document.forms[i].name);
382: }
383: }
384: }
385: }
386:
387: function openWindow(url, wdwName, w, h, toolbar,scrollbar,locationbar) {
388: var xpos = (screen.width-w)/2;
389: xpos = (xpos < 0) ? '0' : xpos;
390: var ypos = (screen.height-h)/2-30;
391: ypos = (ypos < 0) ? '0' : ypos;
392: var options = "width=" + w + ",height=" + h + ",screenx="+xpos+",screeny="+ypos+",";
393: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
394: options += "menubar=no,toolbar="+toolbar+",location="+locationbar+",directories=no";
395: var newWin = window.open(url, wdwName, options);
396: newWin.focus();
397: }
398:
399: function gothere(val) {
400: window.location=val+'?acts='+document.forms.fileattr.acts.value$inhibit_menu;
401: }
402: // ]]>
403: </script>
404: ENDHEADER
405:
406: my ($headerdom)=($uri=~m{^/res/($match_domain)/});
407:
408: if ($env{'form.catalogmode'}) {
409: # "Popup mode"
410: $r->print(&Apache::loncommon::start_page('Browse published resources',$js,
411: {'only_body' => 1, 'add_wishlist'=>1, 'add_modal' =>1,
412: 'domain' => $headerdom,}));
413: } else {
414: # Only display page header and breadcrumbs in non-popup mode
415: &Apache::lonhtmlcommon::clear_breadcrumbs();
416: &Apache::lonhtmlcommon::add_breadcrumb({
417: 'text' => 'Browse published resources',
418: 'href' => '/res/'.$headerdom.'/?launch=1',
419: });
420: $r->print(&Apache::loncommon::start_page('Browse published resources',$js,
421: {'domain' => $headerdom,})
422: .&Apache::lonhtmlcommon::breadcrumbs()
423: );
424: }
425:
426: # ---------------------------------- get state of file types to be showing
427: if ($env{'form.only'}) {
428: $typeselect = $env{'form.only'};
429: } else {
430: $typeselect = '';
431: }
432:
433: # ---------------------------------- get state of file attributes to be showing
434: if ($env{'form.attrs'}) {
435: for (my $i=0; $i<=16; $i++) {
436: delete $hash{'display_attrs_'.$i};
437: if ($env{'form.attr'.$i} == 1) {
438: $attrchk[$i] = 'checked';
439: $hash{'display_attrs_'.$i} = 1;
440: }
441: }
442: } else {
443: for (my $i=0; $i<=16; $i++) {
444: $attrchk[$i] = 'checked="checked"' if $hash{'display_attrs_'.$i} == 1;
445: }
446: }
447:
448: my @file_categories = &Apache::loncommon::filecategories();
449: my %select_file_categories;
450: my @select_form_order = ('');
451: $select_file_categories{''} = &mt('All file types');
452: foreach my $cat (@file_categories) {
453: my $types = join(",",&Apache::loncommon::filecategorytypes($cat));
454: $select_file_categories{$types} = &mt($cat);
455: push(@select_form_order,$types);
456: }
457: $select_file_categories{'select_form_order'} = \@select_form_order;
458: my $onchange = 'this.form.submit();';
459: my $type_element=
460: &Apache::loncommon::select_form(
461: $typeselect,
462: 'only',
463: \%select_file_categories,$onchange);
464: my $type_selector = '<label>'.&mt('File Type Displayed: [_1]',
465: $type_element).'</label>';
466:
467: # ------------------------------- output state of file attributes to be showing
468: # All versions has to the last item
469: # since it does not take an extra col
470: my %lt=&Apache::lonlocal::texthash(
471: 'av' => 'All versions',
472: 'ud' => 'Update Display',
473: 'pr' => 'Problems',
474: 'gr' => 'Graphics',
475: 'at' => 'All types',
476: 'hd' => 'Display Options'
477: );
478: my @disp_order = ('0','4','5','6','13','1','2','3','10','14','8','11','7','12','15','16');
479: my %disp_options = &Apache::lonlocal::texthash (
480: 0 => 'Title',
481: 4 => 'Author',
482: 5 => 'Keywords',
483: 6 => 'Language',
484: 13 => 'Notes',
485: 1 => 'Size',
486: 2 => 'Last access',
487: 3 => 'Last modified',
488: 10 => 'Source Available',
489: 14 => 'Abstract',
490: 8 => 'Statistics',
491: 11 => 'Linked/Related Resources',
492: 7 => 'Show resource',
493: 12 => 'Subject',
494: 15 => 'Grade Level',
495: 16 => 'Standards',
496: );
497: my $cell = 0;
498: my $numinrow = 4;
499: $r->print('
500: <form method="post" name="fileattr" action="'.$uri.'" enctype="application/x-www-form-urlencoded">
501: <fieldset>
502: <legend>'.$lt{'hd'}.'</legend>
503: <table style=" border-collapse: collapse; border-style: none;">'."\n");
504: foreach my $item (@disp_order) {
505: my $style = 'padding-left: 12px; padding-right: 8px;';
506: if ($cell%$numinrow == 0) {
507: $r->print('<tr>');
508: }
509: $cell ++;
510: if ($cell > 3 * $numinrow) {
511: $style .= ' padding-bottom: 6px;';
512: }
513: if (defined($disp_options{$item})) {
514: $r->print('<td style="'.$style.'"><span class="LC_nobreak">'.
515: '<label><input type="checkbox" name="attr'.$item.'" value="1" '.
516: $attrchk[$item].' onclick="this.form.submit();" /> '.$disp_options{$item}.
517: '</label></span></td>'."\n");
518: }
519: if ($cell > 1 && $cell%$numinrow == 0) {
520: $r->print('</tr>');
521: }
522: }
523: $r->print(<<END);
524: <tr>
525: <td style="font-style: italic; border-top: 1px solid black; padding-top: 6px">
526: <label><input type="checkbox" name="attr9" value="1" $attrchk[9] onclick="this.form.submit();" /> $lt{'av'}</label>
527: </td>
528: <td colspan="3" style="padding-left:8px; padding-top: 4px; font-style: italic; border-top: 1px solid black; padding-top: 8px">$type_selector</td>
529: </tr>
530: </table>
531: <input type="hidden" name="attrs" value="1" />
532: </fieldset>
533: <input type="submit" name="updatedisplay" value="$lt{'ud'}" />
534: <input type="hidden" name="acts" value="" />
535: $closebutton $groupimportbutton
536: END
537: $r->print(&Apache::loncommon::inhibit_menu_check('input'));
538:
539: # -------------- Filter out sequence containment in crumbs and "recent folders"
540: my $storeuri=$uri;
541: $storeuri='/'.(split(/\.(page|sequence)\/\//,$uri))[-1];
542: $storeuri=~s/\/+/\//g;
543: # ---------------------------------------------------------------- Bread crumbs
544: $r->print(
545: '<p>'
546: .&Apache::lonhtmlcommon::crumbs(
547: $storeuri,
548: '',
549: '',
550: (($env{'form.catalogmode'} eq 'import')?
551: 'document.forms.fileattr':''))
552: .'<br />'
553: .&Apache::lonhtmlcommon::select_recent(
554: 'residx',
555: 'resrecent',
556: '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();')
557: .'</p>'
558: );
559: # -------------------------------------------------------- Resource Home Button
560: my $reshome=$env{'course.'.$env{'request.course.id'}.'.reshome'};
561: if ($reshome) {
562: $r->print("<span class=\"LC_fontsize_large\"><a href='");
563: if ($env{'form.catalogmode'} eq 'import') {
564: $r->print('javascript:document.forms.fileattr.action="'.&Apache::loncommon::inhibit_menu_check($reshome).'";document.forms.fileattr.submit();');
565: } else {
566: $r->print($reshome);
567: }
568: $r->print("'>".&mt('Home directory').'</a></span>');
569: }
570: $r->print('</form>');
571: # ------------------------------------------------------ Remember where we were
572: &Apache::loncommon::storeresurl($storeuri);
573: &Apache::lonhtmlcommon::store_recent('residx',$storeuri,$storeuri);
574: # -------------------------------------------------- Check All and Uncheck all
575: if ($env{'form.catalogmode'} eq 'import') {
576: $r->print('<p><input type="button" value="'.&mt("Check All").'" id="checkallbutton" onclick="javascript:checkAll()" />');
577: $r->print('<input type="button" value="'.&mt("Uncheck All").'" id="uncheckallbutton" onclick="javascript:uncheckAll()" /></p>');
578: }
579: # ----------------- output starting row to the indexed file/directory hierarchy
580: #$r->print(&initdebug());
581: #$r->print(&writedebug("Omit:@Omit")) if (@Omit);
582: #$r->print(&writedebug("Only:@Only")) if (@Only);
583: $r->print(&Apache::loncommon::start_data_table("LC_tableBrowseRes")
584: .&Apache::loncommon::start_data_table_header_row());
585: $r->print("<th $colspan>".&mt('Name')."</th>\n");
586: $r->print("<th></th>\n");
587: $r->print("<th>".&mt('Title')."</th>\n")
588: if ($hash{'display_attrs_0'} == 1);
589: $r->print('<th class="LC_right">'.&mt("Size")." (".&mt("bytes").") ".
590: "</th>\n") if ($hash{'display_attrs_1'} == 1);
591: $r->print("<th>".&mt("Last accessed")."</th>\n")
592: if ($hash{'display_attrs_2'} == 1);
593: $r->print("<th>".&mt("Last modified")."</th>\n")
594: if ($hash{'display_attrs_3'} == 1);
595: $r->print("<th>".&mt("Author(s)")."</th>\n")
596: if ($hash{'display_attrs_4'} == 1);
597: $r->print("<th>".&mt("Keywords")."</th>\n")
598: if ($hash{'display_attrs_5'} == 1);
599: $r->print("<th>".&mt("Language")."</th>\n")
600: if ($hash{'display_attrs_6'} == 1);
601: $r->print("<th>".&mt("Usage Statistics")." <br />(".
602: &mt("Courses/Network Hits").") ".&mt('updated periodically')."</th>\n")
603: if ($hash{'display_attrs_8'} == 1);
604: $r->print("<th>".&mt("Source Available")."</th>\n")
605: if ($hash{'display_attrs_10'} == 1);
606: $r->print("<th>".&mt("Linked/Related Resources")."</th>\n")
607: if ($hash{'display_attrs_11'} == 1);
608: $r->print("<th>".&mt("Resource")."</th>\n")
609: if ($hash{'display_attrs_7'} == 1);
610: $r->print("<th>".&mt("Subject")."</th>\n")
611: if ($hash{'display_attrs_12'} == 1);
612: $r->print("<th>".&mt("Notes")."</th>\n")
613: if ($hash{'display_attrs_13'} == 1);
614: $r->print("<th>".&mt("Abstract")."</th>\n")
615: if ($hash{'display_attrs_14'} == 1);
616: $r->print("<th>".&mt("Grade Level")."</th>\n")
617: if ($hash{'display_attrs_15'} == 1);
618: $r->print("<th>".&mt("Standards")."</th>\n")
619: if ($hash{'display_attrs_16'} == 1);
620:
621: $r->print(&Apache::loncommon::end_data_table_header_row());
622:
623:
624:
625: # ----------------- read in what directories have previously been set to "open"
626: foreach (keys(%hash)) {
627: if ($_ =~ /^diropen_status_/) {
628: my $key = $_;
629: $key =~ s/^diropen_status_//;
630: $dirs{$key} = $hash{$_};
631: }
632: }
633:
634: if ($env{'form.openuri'}) { # take care of review and refresh options
635: my $uri=$env{'form.openuri'};
636: if (exists($hash{'diropen_status_'.$uri})) {
637: my $cursta = $hash{'diropen_status_'.$uri};
638: $dirs{$uri} = 'open';
639: $hash{'diropen_status_'.$uri} = 'open';
640: if ($cursta eq 'open') {
641: $dirs{$uri} = 'closed';
642: $hash{'diropen_status_'.$uri} = 'closed';
643: }
644: } else {
645: $hash{'diropen_status_'.$uri} = 'open';
646: $dirs{$uri} = 'open';
647: }
648: }
649:
650: my $toplevel;
651: my $indent = 0;
652: $uri = $uri.'/' if $uri !~ /.*\/$/;
653:
654: if ($env{'form.dirPointer'} ne 'on') {
655: $hash{'top.level'} = $uri;
656: $toplevel = $uri;
657: } else {
658: $toplevel = $hash{'top.level'};
659: }
660:
661: # -------------------------------- if not at top level, provide an uplink arrow
662: if ($toplevel ne '/res/'){
663: my (@uri_com) = split(/\//,$uri);
664: pop @uri_com;
665: my $upone = join('/',@uri_com);
666: my @list = qw (0);
667: &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
668: $indent = 1;
669: }
670:
671: # -------- recursively go through all the directories and output as appropriate
672: &scanDir ($r,$toplevel,$indent,\%hash);
673:
674: # -------------------------------------------------------------- end the tables
675: $r->print(&Apache::loncommon::end_data_table());
676:
677: # ---------------------------- embed hidden information useful for group import
678: $r->print("<form name='fnum' action=''>");
679: $r->print("<input type='hidden' name='fnum' value='$fnum' /></form>");
680:
681: # --------------------------------------------------- end the output and return
682: $r->print(&Apache::loncommon::end_page()."\n");
683: }
684: if(! $c->aborted()) {
685: # write back into the temporary file
686: my %dbfile;
687: if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_NEWDB(),0640)) {
688: while (my($key,$value) = each(%hash)) {
689: $dbfile{$key}=$value;
690: }
691: untie(%dbfile);
692: }
693: }
694:
695: return OK;
696: }
697:
698: # ----------------------------------------------- recursive scan of a directory
699: sub scanDir {
700: my ($r,$startdir,$indent,$hashref)=@_;
701: my $c = $r->connection();
702: my ($compuri,$curdir);
703: my $dirptr=16384;
704: my $obs;
705: $indent++;
706: my %dupdirs = %dirs;
707: my @list=&get_list($r,$startdir);
708: foreach my $line (@list) {
709: return if ($c->aborted());
710: #This is a kludge, sorry aboot this
711: my ($strip,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
712: next if($strip =~ /.*\.meta$/ | $obs eq '1');
713: my (@fileparts) = split(/\./,$strip);
714: if ($hash{'display_attrs_9'} != 1) {
715: # if not all versions to be shown
716: if (scalar(@fileparts) >= 3) {
717: my $fext = pop @fileparts;
718: my $ov = pop @fileparts;
719: my $fname = join ('.',@fileparts,$fext);
720: next if (grep /\Q$fname\E/,@list and $ov =~ /^\d+$/);
721: }
722: }
723:
724: if ($dom eq 'domain') {
725: # dom list has full path /res/<domain name>/ already
726: $curdir='';
727: $compuri = (split(/\&/,$line))[0];
728: } else {
729: # user, dir & file have name only, i.e., w/o path
730: $compuri = join('',$startdir,$strip,'/');
731: $curdir = $startdir;
732: }
733: my $diropen = 'closed';
734: if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/) or ($compuri=~/\.(sequence|page)\/$/)) {
735: while (my ($key,$val)= each %dupdirs) {
736: if ($key eq $compuri and $val eq "open") {
737: $diropen = "opened";
738: delete($dupdirs{$key});
739: delete($dirs{$key});
740: }
741: }
742: }
743: &display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
744: &scanDir ($r,$compuri,$indent) if $diropen eq 'opened';
745: }
746: $indent--;
747: }
748:
749: # --------------- get complete matched list based on the uri (returns an array)
750: sub get_list {
751: my ($r,$uri)=@_;
752: my @list=();
753: my $listerror;
754:
755: (my $luri = $uri) =~ s/\//_/g;
756: if ($env{'form.updatedisplay'}) {
757: foreach (keys(%hash)) {
758: delete $hash{$_} if ($_ =~ /^dirlist_files_/);
759: delete $hash{$_} if ($_ =~ /^dirlist_timestamp_files_/);
760: }
761: }
762:
763: if (defined($hash{'dirlist_files_'.$luri}) &&
764: $hash{'dirlist_timestamp_files_'.$luri}+600 > (time)) {
765: @list = split(/\n/,$hash{'dirlist_files_'.$luri});
766: } elsif ($uri=~/\.(page|sequence)\/$/) {
767: # is a page or a sequence
768: $uri=~s/\/$//;
769: $uri='/'.(split(/\.(page|sequence)\/\//,$uri))[-1];
770: $uri=~s/\/+/\//g;
771: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$uri))) {
772: my @ratpart=split(/\:/,$_);
773: push(@list,&LONCAPA::map::qtescape($ratpart[1]));
774: }
775: $hash{'dirlist_files_'.$luri} = join("\n",@list);
776: } else {
777: # is really a directory
778: (my $listref,$listerror) = &Apache::lonnet::dirlist($uri);
779: if (ref($listref) eq 'ARRAY') {
780: @list = @{$listref};
781: }
782: $hash{'dirlist_files_'.$luri} = join("\n",@list);
783: $hash{'dirlist_timestamp_files_'.$luri} = time;
784: }
785: #Checking for error messages associated with empty directories or inaccessible servers (See Bug 4984)
786: if (($listerror eq 'no_such_dir') || ($listerror eq 'no_such_host') || ($listerror eq 'no_host')) {
787: $r->print("<p class='LC_info'>" . &mt("Directory does not exist."). "</p>");
788: } elsif ($listerror eq 'con_lost') {
789: $r->print("<p class='LC_info'>" . &mt("Directory temporarily not accessible."). "</p>");
790: }
791:
792: return @list=&match_ext($r,@list);
793: }
794:
795: sub dynmetaread {
796: my $uri=shift;
797: if (($hash{'display_attrs_8'}==1) || ($hash{'display_attrs_11'}==1)) {
798: # We don't want the filename
799: $uri=~s/\/[^\/]+$//;
800: # Did we already see this?
801: my $builddir=$uri;
802: while ($builddir) {
803: if ($dynread{$builddir}) {
804: return 0;
805: }
806: $builddir=~s/\/[^\/]+$//;
807: }
808: # Actually get the data
809: %dynhash=
810: (%dynhash,&Apache::lonmeta::get_dynamic_metadata_from_sql($uri.'/'));
811: # Remember that we got it
812: $dynread{$uri}=1;
813: }
814: }
815:
816: sub initdebug {
817: my $start_page=
818: &Apache::loncommon::start_page('Debug',undef,
819: {'only_body' => 1,});
820: $start_page =~ s/\n/ /g;
821: return <<ENDJS;
822: <script type="text/javascript">
823: var debugging = true;
824: if (debugging) {
825: var debuggingWindow = window.open('','Debug','width=400,height=300',true);
826: }
827:
828: function output(text) {
829: if (debugging) {
830: debuggingWindow.document.writeln(text);
831: }
832: }
833: output('$start_page<pre>');
834: </script>
835: ENDJS
836: }
837:
838: sub writedebug {
839: my ($text) = @_;
840: return "<script type=\"text/javascript\">output('$text');</script>";
841: }
842:
843: # -------------------- filters out files based on extensions (returns an array)
844: sub match_ext {
845: my ($r,@packlist)=@_;
846: my @trimlist;
847: my $nextline;
848: my @fileext;
849: my $dirptr=16384;
850:
851: foreach my $line (@packlist) {
852: chomp $line;
853: $line =~ s/^\/home\/httpd\/html//;
854: my @unpackline = split (/\&/,$line);
855: next if ($unpackline[0] eq '.');
856: next if ($unpackline[0] eq '..');
857: my @filecom = split (/\./,$unpackline[0]);
858: my $fext = pop(@filecom);
859: my $fnptr = ($unpackline[3]&$dirptr) || ($fext=~/\.(page|sequence)$/);
860: if ($fnptr == 0 and $unpackline[3] ne "") {
861: my $embstyle = &Apache::loncommon::fileembstyle($fext);
862: push @trimlist,$line if (defined($embstyle) &&
863: ($embstyle ne 'hdn' or $fext eq 'meta'));
864: } else {
865: push @trimlist,$line;
866: }
867: }
868: @trimlist = sort {uc($a) cmp uc($b)} (@trimlist);
869: return @trimlist;
870: }
871:
872: # ------------------------------- displays one line in appropriate table format
873: sub display_line {
874: my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
875: my (@pathfn, $fndir);
876: # there could be relative paths (files actually belonging into this directory)
877: # or absolute paths (for example, from sequences)
878: my $absolute;
879: my $pathprefix;
880: if ($line=~m|^/res/| && $startdir ne '') {
881: $absolute=1;
882: $pathprefix='';
883: } else {
884: $absolute=0;
885: $pathprefix=$startdir;
886: }
887: my $dirptr=16384;
888: #SB my $fileclr="#ffffe6";
889: my $iconpath= $r->dir_config('lonIconsURL') . '/';
890:
891: my @filecom = split (/\&/,$line);
892: my @pathcom = split (/\//,$filecom[0]);
893: my $listname = $pathcom[scalar(@pathcom)-1];
894: my $fnptr = $filecom[3]&$dirptr;
895: my $msg = &mt('View').' '.$filecom[0].' '.&mt('resources');
896: $msg = &mt('Close').' '.$filecom[0].' '.&mt('directory') if $diropen eq 'opened';
897: my $nowOpen = ($diropen eq 'opened' ? 1 : 0);
898:
899: my $tabtag='</td>';
900: my $i=0;
901: while ($i<=16) {
902: $tabtag=join('',$tabtag,"<td> </td>")
903: if ($i != 9 &&
904: $hash{'display_attrs_'.$i} == 1);
905: $i++;
906: }
907: my $valign = ($hash{'display_attrs_7'} == 1 ? 'top' : 'bottom');
908:
909: # display uplink arrow
910: if ($filecom[1] eq 'viewOneUp') {
911: my $updir=$startdir;
912: # -------------- Filter out sequence containment in crumbs and "recent folders"
913: $updir='/'.(split(/\.(page|sequence)\/\//,$startdir))[-1];
914: $updir=~s/\/+/\//g;
915:
916: #SB $r->print("<tr valign='$valign' bgcolor=\"$fileclr\">$extrafield");
917: $r->print(&Apache::loncommon::start_data_table_row()); # valign="$valign" ?!?
918: $r->print($extrafield);
919: $r->print("<td>\n");
920: $r->print ('<form method="post" name="dirpathUP" action="'.$updir.
921: '/" '.
922: 'onsubmit="return rep_dirpath(\'UP\','.
923: 'document.forms.fileattr.acts.value)" '.
924: 'enctype="application/x-www-form-urlencoded"'.
925: '>'."\n");
926: $r->print(&Apache::loncommon::inhibit_menu_check('input'));
927: $r->print ('<input type="hidden" name="openuri" value="'.
928: $startdir.'" />'."\n");
929: $r->print ('<input type="hidden" name="acts" value="" />'."\n");
930: $r->print ('<a href="#" onclick="document.dirpathUP.submit()"><img src="'.$iconpath.'arrow.up.gif"');
931: $r->print (' alt="'.$msg.'" class="LC_fileicon" />'.
932: "\n");
933: $r->print(&mt("Up")."</a></form></td><td>$tabtag");
934: $r->print(&Apache::loncommon::end_data_table_row());
935: return OK;
936: }
937: # Do we have permission to look at this?
938: if($filecom[15] ne '1') { return OK if ((!&Apache::lonnet::allowed('bre',$pathprefix.$filecom[0])) && (!&Apache::lonnet::allowed('bro',$pathprefix.$filecom[0]))); }
939:
940: # make absolute links appear on different background
941: #SB if ($absolute) { $fileclr='#ccdd99'; }
942:
943: # display domain
944: if ($filecom[1] eq 'domain') {
945: $r->print ('<input type="hidden" name="dirPointer" value="on" />'."\n")
946: if ($env{'form.dirPointer'} eq "on");
947: #SB $r->print("<tr valign='$valign' bgcolor=\"$fileclr\">$extrafield");
948: $r->print(&Apache::loncommon::start_data_table_row()); # valign="$valign" ?!?"
949: $r->print($extrafield);
950: $r->print("<td>");
951: &begin_form ($r,$filecom[0]);
952: my $anchor = $filecom[0];
953: $anchor =~ s/\W//g;
954: $r->print ('<a name="'.$anchor.'"></a>');
955: $r->print ('<input type="hidden" name="acts" value="" />');
956: $r->print ('<a href="#" onclick="document.dirpath'.($dnum-1).'.submit()"><img src="'.$iconpath.'arrow.'.($nowOpen ? "open" : "closed" ).'.gif"');
957: $r->print (' alt="'.$msg.'" class="LC_fileicon" /></a>'.
958: "\n");
959: my $quotable_filecom = &Apache::loncommon::escape_single($filecom[0]);
960: $r->print ('<a href="javascript:gothere(\''.$quotable_filecom.
961: '\')"><img alt="" src="'.$iconpath.'server.gif"');
962: $r->print (' class="LC_fileicon" />'."\n");
963: $r->print (&mt("Domain")." - $listname </a>");
964: if (&Apache::lonnet::domain($listname,'description')) {
965: $r->print("<br />(".&Apache::lonnet::domain($listname,'description').
966: ")");
967: }
968: $r->print("</form></td><td>$tabtag");
969: $r->print(&Apache::loncommon::end_data_table_row());
970: return OK;
971:
972: # display user directory
973: }
974: if ($filecom[1] eq 'user') {
975: # $r->print("<tr valign=$valign bgcolor=\"$fileclr\">$extrafield");
976: my $curdir = $startdir.$filecom[0].'/';
977: my $anchor = $curdir;
978: $anchor =~ s/\W//g;
979: #SB $r->print("<tr bgcolor=\"$fileclr\">$extrafield<td valign=$valign>");
980: $r->print(&Apache::loncommon::start_data_table_row()
981: .$extrafield.'<td class="LC_'.$valign.'">');
982: &begin_form ($r,$curdir);
983: $r->print ('<a name="'.$anchor.'"></a><img alt="" src="'.$iconpath.
984: 'whitespace_21.gif" class="LC_icon" />'."\n");
985: $r->print ('<input type="hidden" name="acts" value="" />');
986: $r->print ('<a href="#" onclick="document.dirpath'.($dnum-1).'.submit()">');
987: $r->print ('<img src="'.$iconpath.'arrow.'.($nowOpen ? "open" : "closed" ).
988: '.gif" class="LC_fileicon"');
989: $r->print (' alt="'.$msg.'"/></a>'.
990: "\n");
991: my $quotable_curdir = &Apache::loncommon::escape_single($curdir);
992: my $quotable_startdir = &Apache::loncommon::escape_single($startdir);
993: my $quotable_listname = &Apache::loncommon::escape_single($listname);
994:
995: $r->print ('<a href="javascript:gothere(\''.$quotable_curdir
996: .'\')"><img alt="'.$msg.'" src="'.
997: $iconpath.'quill.gif" class="LC_fileicon" />');
998: my $domain=(split(m|/|,$startdir))[2];
999: my $plainname=&Apache::loncommon::plainname($listname,$domain);
1000: $r->print ($listname.'</a>');
1001:
1002: if (defined($plainname) && $plainname) { $r->print(" ($plainname) "); }
1003: # Wishlistlink
1004: $r->print('</form></td><td><a href="javascript:;" '.
1005: 'title="'.&mt('Save a link for this folder in your personal Stored Links repository').'" '.
1006: 'onclick="set_wishlistlink('."'$plainname','$quotable_startdir$quotable_listname"."/'".')">'.
1007: '<img class="LC_icon" src="/res/adm/pages/wishlist.png" '.
1008: 'alt="'.&mt('save in Stored Links').'" style="width:22px;"/></a>'.$tabtag);
1009: $r->print(&Apache::loncommon::end_data_table_row());
1010: return OK;
1011: }
1012:
1013: # display file
1014: if (($fnptr == 0 and $filecom[3] ne '') or $absolute) {
1015: my $title;
1016: my $filelink = $pathprefix.$filecom[0];
1017: if ($hash{'display_attrs_0'} == 1) {
1018: $title = &Apache::lonnet::gettitle($filelink);
1019: }
1020: my @file_ext = split (/\./,$listname);
1021: my $curfext = $file_ext[-1];
1022: if (@Omit) {
1023: foreach (@Omit) { return OK if (lc($curfext) eq $_); }
1024: }
1025: if (@Only) {
1026: my $skip = 1;
1027: foreach (@Only) { $skip = 0 if (lc($curfext) eq $_); }
1028: return OK if ($skip > 0);
1029: }
1030: # Set the icon for the file
1031: my $iconname = &Apache::loncommon::icon($listname);
1032: #SB $r->print("<tr valign='$valign' bgcolor=\"$fileclr\">);
1033: $r->print(&Apache::loncommon::start_data_table_row()); #SB valign="$valign" ?!?
1034: $r->print('<td class="LC_middle LC_nobreak">');
1035:
1036: if ($env{'form.catalogmode'} eq 'interactive') {
1037: my $quotable_filelink = &Apache::loncommon::escape_single($filelink);
1038: $r->print("<a href=\"javascript:select_data(\'",
1039: $quotable_filelink,"')\">");
1040: $r->print("<img alt=\"\" src='",$iconpath,"select.gif' class='LC_icon' /></a>".
1041: "\n");
1042: $r->print('</td><td class="LC_middle">');
1043: } elsif ($env{'form.catalogmode'} eq 'import') {
1044: $r->print("<form name='form$fnum' action=''>\n");
1045: $r->print("<input type='checkbox' name='filelink"."' ".
1046: "value='$filelink' onclick='".
1047: "javascript:queue(\"form$fnum\")' ");
1048: if ($hash{'store_'.$filelink}) {
1049: $r->print("checked");
1050: }
1051: $r->print(" />\n");
1052: $r->print('</form></td><td class="LC_middle">');
1053: $hash{"pre_${fnum}_link"}=$filelink;
1054: $hash{"pre_${fnum}_title"}=$title;
1055: if (!$hash{"pre_${fnum}_title"}) {
1056: $hash{"pre_${fnum}_title"} = 'Not_retrieved';
1057: }
1058: $fnum++;
1059: }
1060: # Form to open or close sequences
1061: if ($filelink=~/\.(page|sequence)$/) {
1062: my $curdir = $startdir.$filecom[0].'/';
1063: &begin_form($r,$curdir);
1064: $indent--;
1065: }
1066: # General indentation
1067: my $count = 0;
1068: while ($count < $indent) {
1069: $r->print('<img alt="" src="'.$iconpath.'whitespace_21.gif"
1070: class="LC_icon" />');
1071: $count++;
1072: }
1073: # Sequence open/close icon
1074: if ($filelink=~/\.(page|sequence)$/) {
1075: my $curdir = $startdir.$filecom[0].'/';
1076: my $anchor = $curdir;
1077: $anchor =~ s/\W//g;
1078: $r->print ('<input type="hidden" name="acts" value="" />');
1079: $r->print ('<a name="'.$anchor.'"></a>');
1080: $r->print ('<a href="#" onclick="document.dirpath'.($dnum-1).'.submit()">');
1081: $r->print ('<img src="'.$iconpath.'arrow.'.($nowOpen ? "open" : "closed" ).
1082: '.gif" class="LC_fileicon"');
1083: $r->print (' alt="'.$msg.'" /></a>'.
1084: "\n");
1085: }
1086: # Filetype icons
1087: $r->print("<img alt=\"\" src='$iconname' class='LC_fileicon' />\n");
1088: my $quotable_filelink = &Apache::loncommon::escape_single($filelink);
1089: my $quotable_startdir = Apache::loncommon::escape_single($startdir);
1090: my $quotable_listname = &Apache::loncommon::escape_single($listname);
1091: my $curfext = lc((split(/\./,$listname))[-1]);
1092: my $modalstyle;
1093: if ($curfext =~ /^js|css|txt|tab$/) {
1094: $modalstyle = ",'','background-color:#ffffff'";
1095: }
1096:
1097: $r->print (" <a href=\"javascript:openMyModal('".$quotable_filelink."?inhibitmenu=yes',500,500,'yes'".$modalstyle.");\">$listname</a> ");
1098: $quotable_filelink = &Apache::loncommon::escape_single($filelink.'.meta');
1099: &Apache::loncommon::inhibit_menu_check(\$quotable_filelink);
1100: $r->print (" (<a href=\"javascript:openMyModal('".$quotable_filelink."?inhibitmenu=yes',500,500,'yes');\">".&mt('metadata')."</a>) ");
1101: # Close form to open/close sequence
1102: if ($filelink=~/\.(page|sequence)$/) {
1103: $r->print('</form>');
1104: }
1105: $r->print("</td>\n");
1106: # Wishlistlink
1107: $r->print('<td><a href="javascript:;" title="'.&mt('Save a link for this resource in your personal Stored Links repository').'" '.
1108: 'onclick="set_wishlistlink('."'".&Apache::lonnet::gettitle($filelink).
1109: "','$quotable_startdir$quotable_listname'".')">'.
1110: '<img class="LC_icon" src="/res/adm/pages/wishlist.png" '.
1111: 'alt="'.&mt('save in Stored Links').'" style="width:22px;"/></a></td>');
1112: if ($hash{'display_attrs_0'} == 1) {
1113: $r->print('<td> '.($title eq '' ? ' ' : $title).
1114: ' </td>'."\n");
1115: }
1116: $r->print('<td class="LC_right"> ',
1117: $filecom[8]," </td>\n")
1118: if $hash{'display_attrs_1'} == 1;
1119: $r->print('<td class="LC_nobreak"> '.
1120: (&Apache::lonlocal::locallocaltime($filecom[9]))." </td>\n")
1121: if $hash{'display_attrs_2'} == 1;
1122: $r->print('<td class="LC_nobreak"> '.
1123: (&Apache::lonlocal::locallocaltime($filecom[10]))." </td>\n")
1124: if $hash{'display_attrs_3'} == 1;
1125:
1126: if ($hash{'display_attrs_4'} == 1) {
1127: my $author = &Apache::lonnet::metadata($filelink,'author');
1128: $r->print('<td class="LC_nobreak"> '.($author eq '' ? ' ' : $author).
1129: " </td>\n");
1130: }
1131: if ($hash{'display_attrs_5'} == 1) {
1132: my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
1133: # $keywords = ' ' if (!$keywords);
1134: $r->print('<td> '.($keywords eq '' ? ' ' : $keywords).
1135: " </td>\n");
1136: }
1137:
1138: if ($hash{'display_attrs_6'} == 1) {
1139: my $lang = &Apache::lonnet::metadata($filelink,'language');
1140: $lang = &Apache::loncommon::languagedescription($lang);
1141: $r->print('<td> '.($lang eq '' ? ' ' : $lang).
1142: " </td>\n");
1143: }
1144: if ($hash{'display_attrs_8'} == 1) {
1145: # statistics
1146: &dynmetaread($filelink);
1147: $r->print("<td>");
1148:
1149: for (qw(count course stdno avetries difficulty disc clear technical
1150: correct helpful depth)) {
1151:
1152: dynmetaprint($r,$filelink,$_);
1153: }
1154:
1155: $r->print(" </td>\n");
1156:
1157: }
1158: if ($hash{'display_attrs_10'} == 1) {
1159: my $source = &Apache::lonnet::metadata($filelink,'sourceavail');
1160: if($source eq 'open') {
1161: my $sourcelink = &Apache::lonsource::make_link($filelink,$listname);
1162: my $quotable_sourcelink = &Apache::loncommon::escape_single($sourcelink);
1163: &Apache::loncommon::inhibit_menu_check(\$quotable_sourcelink);
1164: $r->print('<td>'."<a href=\"javascript:openWindow('"
1165: .$quotable_sourcelink.
1166: "', 'previewsource', '700', '700', 'no', 'yes','yes');\"".
1167: " target=\"_self\">".&mt('Source Code')."</a> "."</td>\n");
1168: } else { #A cuddled else. :P
1169: $r->print("<td> </td>\n");
1170: }
1171: }
1172: if ($hash{'display_attrs_11'} == 1) {
1173: # links
1174: &dynmetaread($filelink);
1175: $r->print('<td>');
1176: &coursecontext($r,$filelink);
1177: for (qw(goto_list comefrom_list sequsage_list dependencies course_list)) {
1178: dynmetaprint($r,$filelink,$_);
1179: }
1180: $r->print('</td>');
1181: }
1182:
1183:
1184:
1185: if ($hash{'display_attrs_7'} == 1) {
1186: # Show resource
1187: my $output=&showpreview($filelink);
1188: $r->print('<td class="LC_fontsize_medium">'.($output eq '' ? ' ':$output).
1189: " </td>\n");
1190: }
1191:
1192: if ($hash{'display_attrs_12'} == 1) {
1193: my $subject = &Apache::lonnet::metadata($filelink,'subject');
1194: $r->print('<td> '.($subject eq '' ? ' ' : $subject).
1195: " </td>\n");
1196: }
1197:
1198: if ($hash{'display_attrs_13'} == 1) {
1199: my $notes = &Apache::lonnet::metadata($filelink,'notes');
1200: $r->print('<td> '.($notes eq '' ? ' ' : $notes).
1201: " </td>\n");
1202: }
1203:
1204: if ($hash{'display_attrs_14'} == 1) {
1205: my $abstract = &Apache::lonnet::metadata($filelink,'abstract');
1206: $r->print('<td> '.($abstract eq '' ? ' ' : $abstract).
1207: " </td>\n");
1208: }
1209:
1210: if ($hash{'display_attrs_15'} == 1) {
1211: my $gradelevel = &Apache::lonnet::metadata($filelink,'gradelevel');
1212: $r->print('<td> '.($gradelevel eq '' ? ' ' : $gradelevel).
1213: " </td>\n");
1214: }
1215:
1216: if ($hash{'display_attrs_16'} == 1) {
1217: my $standards = &Apache::lonnet::metadata($filelink,'standards');
1218: $r->print('<td> '.($standards eq '' ? ' ' : $standards).
1219: " </td>\n");
1220: }
1221:
1222: $r->print(&Apache::loncommon::end_data_table_row());
1223: }
1224:
1225:
1226:
1227: # -- display directory
1228: if ($fnptr == $dirptr) {
1229: my $curdir = $startdir.$filecom[0].'/';
1230: my $anchor = $curdir;
1231: $anchor =~ s/\W//g;
1232: #SB $r->print("<tr bgcolor=\"$fileclr\">$extrafield<td valign=$valign>");
1233: $r->print(&Apache::loncommon::start_data_table_row()); # SB: bgcolor suggestion: darkgrey ("LC_info_row"?!?)
1234: # $r->print('<tr class="LC_info_row">');
1235: $r->print($extrafield.'<td class="LC_middle LC_nobreak">');
1236: &begin_form ($r,$curdir);
1237: my $indentm1 = $indent-1;
1238: my $count = 0;
1239: while ($count < $indentm1) {
1240: $r->print ('<img alt="" src="',$iconpath
1241: ,'whitespace_21.gif" class="LC_icon" />');
1242: $count++;
1243: }
1244: $r->print ('<input type="hidden" name="acts" value="" />');
1245: $r->print ('<a name="'.$anchor.'"></a>');
1246: $r->print ('<a href="#" onclick="document.dirpath'.($dnum-1).'.submit()"><img src="'.$iconpath.
1247: 'arrow.'.($nowOpen ? "open" : "closed" ).'.gif"');
1248: $r->print (' alt="'.$msg.'" class="LC_fileicon" /></a>'.
1249: "\n");
1250: my $quotable_curdir = &Apache::loncommon::escape_single($curdir);
1251: my $quotable_startdir = &Apache::loncommon::escape_single($startdir);
1252: my $quotable_listname = &Apache::loncommon::escape_single($listname);
1253:
1254: my $location = &Apache::loncommon::lonhttpdurl("/adm/lonIcons");
1255: my $icon = "navmap.folder.".($nowOpen ? "open":"closed").'.gif';
1256: $r->print ('<a href="javascript:gothere('
1257: ."'$quotable_curdir'".');">'
1258: .'<img class="LC_fileicon" alt="'.&mt('Open Folder').'" src="'
1259: .$location.'/'.$icon.'" />'
1260: ."\n");
1261: $r->print ("$listname</a></form>");
1262: # Wishlistlink
1263: $r->print('</td><td><a href="javascript:;" '.
1264: 'title="'.&mt('Save a link for this folder in Stored Links').'" '.
1265: 'onclick="set_wishlistlink('."'$listname','$quotable_startdir$quotable_listname"."/'".')">'.
1266: '<img class="LC_icon" src="/res/adm/pages/wishlist.png" '.
1267: 'alt="'.&mt('save in Stored Links').'" style="width:22px;"/></a></td>');
1268: # Attributes
1269: my $filelink = $startdir.$filecom[0].'/default';
1270:
1271: if ($hash{'display_attrs_0'} == 1) {
1272: my $title = &Apache::lonnet::gettitle($filelink);
1273: $r->print('<td> '.($title eq '' ? ' ' : $title).
1274: ' </td>'."\n");
1275: }
1276: $r->print('<td class="LC_right"> ',
1277: $filecom[8]," </td>\n")
1278: if $hash{'display_attrs_1'} == 1;
1279: $r->print('<td class="LC_break"> '.
1280: (&Apache::lonlocal::locallocaltime($filecom[9]))." </td>\n")
1281: if $hash{'display_attrs_2'} == 1;
1282: $r->print('<td class="LC_break"> '.
1283: (&Apache::lonlocal::locallocaltime($filecom[10]))." </td>\n")
1284: if $hash{'display_attrs_3'} == 1;
1285:
1286: if ($hash{'display_attrs_4'} == 1) {
1287: my $author = &Apache::lonnet::metadata($filelink,'author');
1288: $r->print('<td> '.($author eq '' ? ' ' : $author).
1289: " </td>\n");
1290: }
1291: if ($hash{'display_attrs_5'} == 1) {
1292: my $keywords = &Apache::lonnet::metadata($filelink,'keywords');
1293: # $keywords = ' ' if (!$keywords);
1294: $r->print('<td> '.($keywords eq '' ? ' ' : $keywords).
1295: " </td>\n");
1296: }
1297: if ($hash{'display_attrs_6'} == 1) {
1298: my $lang = &Apache::lonnet::metadata($filelink,'language');
1299: $lang = &Apache::loncommon::languagedescription($lang);
1300: $r->print('<td> '.($lang eq '' ? ' ' : $lang).
1301: " </td>\n");
1302: }
1303:
1304: if ($hash{'display_attrs_8'} == 1) {
1305: $r->print('<td> </td>');
1306: }
1307: if ($hash{'display_attrs_10'} == 1) {
1308: $r->print('<td> </td>');
1309: }
1310: if ($hash{'display_attrs_7'} == 1) {
1311: $r->print('<td> </td>');
1312: }
1313: if ($hash{'display_attrs_11'} == 1) {
1314: $r->print('<td> </td>');
1315: }
1316: if ($hash{'display_attrs_12'} == 1) {
1317: my $subject = &Apache::lonnet::metadata($filelink,'subject');
1318: $r->print('<td> '.($subject eq '' ? ' ' : $subject).
1319: " </td>\n");
1320: }
1321: if ($hash{'display_attrs_13'} == 1) {
1322: my $notes = &Apache::lonnet::metadata($filelink,'notes');
1323: $r->print('<td> '.($notes eq '' ? ' ' : $notes).
1324: " </td>\n");
1325: }
1326:
1327: if ($hash{'display_attrs_14'} == 1) {
1328: my $abstract = &Apache::lonnet::metadata($filelink,'abstract');
1329: $r->print('<td> '.($abstract eq '' ? ' ' : $abstract).
1330: " </td>\n");
1331: }
1332:
1333: if ($hash{'display_attrs_15'} == 1) {
1334: my $gradelevel = &Apache::lonnet::metadata($filelink,'gradelevel');
1335: $r->print('<td> '.($gradelevel eq '' ? ' ' : $gradelevel).
1336: " </td>\n");
1337: }
1338:
1339: if ($hash{'display_attrs_16'} == 1) {
1340: my $standards = &Apache::lonnet::metadata($filelink,'standards');
1341: $r->print('<td> '.($standards eq '' ? ' ' : $standards).
1342: " </td>\n");
1343: }
1344:
1345:
1346: $r->print(&Apache::loncommon::end_data_table_row());
1347: }
1348:
1349: }
1350:
1351: sub coursecontext {
1352: my ($r,$filelink)=@_;
1353: my $filesymb=&Apache::lonnet::symbread($filelink);
1354: if ($filesymb) {
1355: my ($map,$index,$resource)=&Apache::lonnet::decode_symb($filesymb);
1356: $r->print(
1357: &mt('Already in this course:').'<br />'
1358: .&mt('[_1] in folder/map [_2]',
1359: &Apache::lonnet::gettitle($resource),
1360: &Apache::lonnet::gettitle($map))
1361: .'<br />');
1362: }
1363: }
1364:
1365: sub showpreview {
1366: my ($filelink)=@_;
1367: if ($filelink=~m-^(/ext/|https?://)-) {
1368: return &mt('External Resource, preview not enabled');
1369: }
1370: my ($curfext)=($filelink=~/\.(\w+)$/);
1371: my $output='';
1372: my $embstyle=&Apache::loncommon::fileembstyle($curfext);
1373: if ($embstyle eq 'ssi') {
1374: my $cache=$Apache::lonnet::perlvar{'lonDocRoot'}.$filelink.
1375: '.tmp';
1376: if ((!$env{'form.updatedisplay'}) &&
1377: (-e $cache)) {
1378: open(FH,$cache);
1379: $output=join("\n",<FH>);
1380: close(FH);
1381: } else {
1382: # In update display mode, remove old cache. This is done to retroactively
1383: # clean up course context renderings.
1384: if (-e $cache) {
1385: unlink($cache);
1386: }
1387: $output=&Apache::lonnet::ssi_body($filelink);
1388: # Is access denied? Don't render, don't store
1389: if ($output=~/LONCAPAACCESSCONTROLERRORSCREEN/s) {
1390: $output='';
1391: # Was this rendered in course content? Don't store
1392: } elsif (!&Apache::lonnet::symbread($filelink)) {
1393: open(FH,">$cache");
1394: print FH $output;
1395: close(FH);
1396: }
1397: }
1398: } elsif ($embstyle eq 'img') {
1399: $output='<img alt="'.&mt('Preview').'" src="'.$filelink.'" />';
1400: } elsif ($filelink=~m{^/res/($match_domain)/($match_username)/}) {
1401: $output='<img alt="'.&mt('Preview').'" src="http://'.
1402: &Apache::lonnet::hostname(&Apache::lonnet::homeserver($2,$1)).
1403: '/cgi-bin/thumbnail.gif?url='.$filelink.'" />';
1404: }
1405: return $output;
1406: }
1407:
1408: sub dynmetaprint {
1409: my ($r,$filelink,$item)=@_;
1410: if ($dynhash{$filelink}->{$item}) {
1411: $r->print("\n<br />".$fieldnames{$item}.': '.
1412: &Apache::lonmeta::prettyprint($item,
1413: $dynhash{$filelink}->{$item},
1414: (($env{'form.catalogmode'} ne 'import')?'preview':''),
1415: '',
1416: (($env{'form.catalogmode'} eq 'import')?'document.forms.fileattr':''),1));
1417: }
1418: }
1419:
1420: # ------------------- prints the beginning of a form for directory or file link
1421: sub begin_form {
1422: my ($r,$uri) = @_;
1423: my $anchor = $uri;
1424: $anchor =~ s/\W//g;
1425: $uri=&Apache::loncommon::escape_single($uri);
1426: $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
1427: '#'.$anchor.
1428: '" onsubmit="return rep_dirpath(\''.$dnum.'\''.
1429: ',document.forms.fileattr.acts.value)" '.
1430: 'enctype="application/x-www-form-urlencoded">'."\n");
1431: $r->print ('<input type="hidden" name="openuri" value="'.$uri.'" />'.
1432: "\n");
1433: $r->print ('<input type="hidden" name="dirPointer" value="on" />'."\n");
1434: $r->print(&Apache::loncommon::inhibit_menu_check('input'));
1435: $dnum++;
1436: }
1437:
1438: # --------- settings whenever the user causes the indexer window to be launched
1439: sub start_fresh_session {
1440: my ($hash) = @_;
1441: delete $hash->{'form.catalogmode'};
1442: delete $hash->{'form.mode'};
1443: delete $hash->{'form.form'};
1444: delete $hash->{'form.element'};
1445: delete $hash->{'form.omit'};
1446: delete $hash->{'form.only'};
1447: foreach (keys(%{$hash})) {
1448: delete $hash->{$_} if (/^(pre_|store)/);
1449: }
1450: }
1451:
1452: # ------------------------------------------------------------------- setvalues
1453: sub setvalues {
1454: # setvalues is used in registerurl to synchronize the database
1455: # hash and environment hashes
1456: my ($H1,$h1key,$H2,$h2key) =@_;
1457: #
1458: if (exists $H2->{$h2key}) {
1459: $H1->{$h1key} = $H2->{$h2key};
1460: } elsif (exists $H1->{$h1key}) {
1461: $H2->{$h2key} = $H1->{$h1key};
1462: }
1463: }
1464:
1465: 1;
1466:
1467: sub cleanup {
1468: if (tied(%hash)){
1469: &Apache::lonnet::logthis('Cleanup indexer: hash');
1470: }
1471: return OK;
1472: }
1473:
1474:
1475:
1476:
1477:
1478: =head1 NAME
1479:
1480: Apache::lonindexer - mod_perl module for cross server filesystem browsing
1481:
1482: =head1 SYNOPSIS
1483:
1484: Invoked by /etc/httpd/conf/srm.conf:
1485:
1486: <LocationMatch "^/res.*/$">
1487: SetHandler perl-script
1488: PerlHandler Apache::lonindexer
1489: </LocationMatch>
1490:
1491: =head1 INTRODUCTION
1492:
1493: This module enables a scheme of browsing across a cross server.
1494:
1495: This is part of the LearningOnline Network with CAPA project
1496: described at http://www.lon-capa.org.
1497:
1498: =head1 HANDLER SUBROUTINE
1499:
1500: This routine is called by Apache and mod_perl.
1501:
1502: =over 4
1503:
1504: =item *
1505:
1506: read in machine configuration variables
1507:
1508: =item *
1509:
1510: see if called from an interactive mode
1511:
1512: =item *
1513:
1514: refresh environment with user database values (in %hash)
1515:
1516: =item *
1517:
1518: define extra fields and buttons in case of special mode
1519:
1520: =item *
1521:
1522: set catalogmodefunctions to have extra needed javascript functionality
1523:
1524: =item *
1525:
1526: print header
1527:
1528: =item *
1529:
1530: evaluate actions from previous page (both cumulatively and chronologically)
1531:
1532: =item *
1533:
1534: output title
1535:
1536: =item *
1537:
1538: get state of file attributes to be showing
1539:
1540: =item *
1541:
1542: output state of file attributes to be showing
1543:
1544: =item *
1545:
1546: output starting row to the indexed file/directory hierarchy
1547:
1548: =item *
1549:
1550: read in what directories have previously been set to "open"
1551:
1552: =item *
1553:
1554: if not at top level, provide an uplink arrow
1555:
1556: =item *
1557:
1558: recursively go through all the directories and output as appropriate
1559:
1560: =item *
1561:
1562: information useful for group import
1563:
1564: =item *
1565:
1566: end the tables
1567:
1568: =item *
1569:
1570: end the output and return
1571:
1572: =back
1573:
1574: =head1 OTHER SUBROUTINES
1575:
1576: =over 4
1577:
1578: =item *
1579:
1580: scanDir - recursive scan of a directory
1581:
1582: =item *
1583:
1584: get_list - get complete matched list based on the uri (returns an array)
1585:
1586: =item *
1587:
1588: match_ext - filters out files based on extensions (returns an array)
1589:
1590: =item *
1591:
1592: display_line - displays one line in appropriate table format
1593:
1594: =item *
1595:
1596: begin_form - prints the beginning of a form for directory or file link
1597:
1598: =item *
1599:
1600: start_fresh_session - settings whenever the user causes the indexer window
1601: to be launched
1602:
1603: =back
1604:
1605: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>