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