Annotation of loncom/interface/lonindexer.pm, revision 1.22

1.1       www         1: # The LearningOnline Network with CAPA
1.14      harris41    2: #
1.1       www         3: # Directory Indexer
1.14      harris41    4: #
1.17      harris41    5: # YEAR=1999
                      6: # 5/21/99, 5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14 Gerd Kortemeyer)
1.1       www         7: # 11/23 Gerd Kortemeyer
1.17      harris41    8: # YEAR=2000
1.1       www         9: # 07/20-08/04 H.K. Ng
1.17      harris41   10: # YEAR=2001
1.2       harris41   11: # 05/9-05/19/2001 H. K. Ng
1.4       harris41   12: # 05/21/2001 H. K. Ng
1.6       harris41   13: # 05/23/2001 H. K. Ng
1.17      harris41   14: # 5/31,6/1,6/2,6/15 Scott Harrison
                     15: # 6/26,7/8 H. K. Ng
                     16: # 8/6,8/7,8/10 Scott Harrison
1.18      ng         17: # 8/14 H. K. Ng
1.21      harris41   18: # 8/28,10/15 Scott Harrison
1.7       harris41   19: 
1.1       www        20: package Apache::lonindexer;
                     21: 
                     22: use strict;
                     23: use Apache::lonnet();
                     24: use Apache::Constants qw(:common);
1.2       harris41   25: use Apache::File;
                     26: use GDBM_File;
                     27: 
1.17      harris41   28: my %hash; # tied to a user-specific gdbm file
                     29: my %dirs; # keys are directories, values are the open/close status
                     30: my %language; # has the reference information present in language.tab
                     31: 
                     32: # ----- Values which are set by the handler subroutine and are accessible to
                     33: # -----     other methods.
                     34: my $extrafield; # default extra table cell
                     35: my $fnum; # file counter
                     36: my $dnum; # directory counter
                     37: 
                     38: # ---------------------------------------------------------------------- BEGIN
1.2       harris41   39: sub BEGIN {
1.14      harris41   40:     my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
                     41: 			     '/language.tab');
1.2       harris41   42:     map {
                     43: 	$_=~/(\w+)\s+([\w\s\-]+)/;
                     44: 	$language{$1}=$2;
                     45:     } <$fh>;
                     46: }
1.1       www        47: 
1.17      harris41   48: # ---------------------------------------------------------------- Main Handler
1.1       www        49: sub handler {
                     50:     my $r = shift;
                     51:     $r->content_type('text/html');
                     52:     $r->send_http_header;
                     53:     return OK if $r->header_only;
1.9       harris41   54:     $fnum=0;
1.16      harris41   55:     $dnum=0;
1.22    ! harris41   56:     untie %hash;
1.17      harris41   57: 
                     58: # --------------------------------------------- machine configuration variables
1.10      harris41   59:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.1       www        60:     my $domain  = $r->dir_config('lonDefDomain');
                     61:     my $role    = $r->dir_config('lonRole');
                     62:     my $loadlim = $r->dir_config('lonLoadLim');
                     63:     my $servadm = $r->dir_config('lonAdmEMail');
                     64:     my $sysadm  = $r->dir_config('lonSysEMail');
                     65:     my $lonhost = $r->dir_config('lonHostID');
                     66:     my $tabdir  = $r->dir_config('lonTabDir');
                     67: 
1.7       harris41   68:     my $fileclr='#ffffe6';
1.15      harris41   69:     my $line;
                     70:     my (@attrchk,@openpath);
                     71:     my $uri=$r->uri;
                     72: 
1.7       harris41   73: # -------------------------------------- see if called from an interactive mode
1.17      harris41   74:     &get_unprocessed_cgi();
1.7       harris41   75: 
1.17      harris41   76:     my $closebutton='';
1.7       harris41   77:     my $groupimportbutton='';
                     78:     my $colspan=''; 
1.14      harris41   79: 
                     80:     $extrafield='';
1.17      harris41   81:     my $diropendb = 
                     82: 	"/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
1.15      harris41   83: 
                     84:     if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
                     85: 	if ($ENV{'form.launch'} eq '1') {
1.17      harris41   86: 	    &start_fresh_session();
1.15      harris41   87: 	}
1.17      harris41   88: 
                     89: # -------------------- refresh environment with user database values (in %hash)
1.15      harris41   90: 	if ($hash{'mode_catalog'} eq 'interactive') {
                     91: 	    $ENV{'form.catalogmode'}='interactive';
                     92: 	}
                     93: 	if ($hash{'mode_catalog'} eq 'groupimport') {
                     94: 	    $ENV{'form.catalogmode'}='groupimport';
                     95: 	}
                     96: 
1.17      harris41   97: # --------------------- define extra fields and buttons in case of special mode
1.15      harris41   98: 	if ($ENV{'form.catalogmode'} eq 'interactive') {
                     99: 	    $hash{'mode_catalog'}='interactive';
                    100: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
                    101: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17      harris41  102: 		' border="0" /></td>';
1.15      harris41  103: 	    $colspan=" colspan='2' ";
                    104:             $closebutton=<<END;
1.7       harris41  105: <input type="button" name="close" value='CLOSE' onClick="self.close()">
                    106: END
1.16      harris41  107:         }
1.15      harris41  108: 	elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
                    109: 	    $hash{'mode_catalog'}='groupimport';
                    110: 	    $extrafield='<td bgcolor="'.$fileclr.'" valign="bottom">'.
                    111: 		'<a name="$anchor"><img src="'.$iconpath.'whitespace1.gif"'.
1.17      harris41  112: 		' border="0" /></td>';
1.15      harris41  113: 	    $colspan=" colspan='2' ";
                    114:             $closebutton=<<END;
1.7       harris41  115: <input type="button" name="close" value='CLOSE' onClick="self.close()">
                    116: END
1.15      harris41  117:             $groupimportbutton=<<END;
1.17      harris41  118: <input type="button" name="groupimport" value='GROUP IMPORT'
                    119: onClick="javascript:select_group()">
1.7       harris41  120: END
1.15      harris41  121:         }
1.7       harris41  122: 
1.17      harris41  123: # ------ set catalogmodefunctions to have extra needed javascript functionality
1.15      harris41  124: 	my $catalogmodefunctions='';
                    125: 	if ($ENV{'form.catalogmode'} eq 'interactive' or
                    126: 	    $ENV{'form.catalogmode'} eq 'groupimport') {
                    127: 	    $catalogmodefunctions=<<END;
1.7       harris41  128: function select_data(title,url) {
                    129:     changeTitle(title);
                    130:     changeURL(url);
1.8       harris41  131:     self.close();
                    132: }
                    133: function select_group() {
1.20      harris41  134:     window.location="/adm/groupsort?catalogmode=groupimport&acts="+document.forms.fileattr.acts.value;
1.16      harris41  135: }
1.7       harris41  136: function changeTitle(val) {
                    137:     if (opener.inf.document.forms.resinfo.elements.t) {
                    138:         opener.inf.document.forms.resinfo.elements.t.value=val;
                    139:     }
                    140: }
                    141: function changeURL(val) {
                    142:     if (opener.inf.document.forms.resinfo.elements.u) {
                    143: 	opener.inf.document.forms.resinfo.elements.u.value=val;
                    144:     }
                    145: }
                    146: END
1.15      harris41  147:         }
1.16      harris41  148: 	if ($ENV{'form.catalogmode'} eq 'groupimport') {
                    149: 	    $catalogmodefunctions.=<<END;
                    150: var acts='';
                    151: function queue(val) {
                    152:     if (eval("document.forms."+val+".filelink.checked")) {
                    153: 	var l=val.length;
                    154: 	var v=val.substring(4,l);
                    155: 	document.forms.fileattr.acts.value+='1a'+v+'b';
                    156:     }
                    157:     else {
                    158: 	var l=val.length;
                    159: 	var v=val.substring(4,l);
                    160: 	document.forms.fileattr.acts.value+='0a'+v+'b';
                    161:     }
                    162: }
                    163: function rep_dirpath(suffix,val) {
                    164:     eval("document.forms.dirpath"+suffix+".acts.value=val");
                    165: }
                    166: END
                    167: 	}
1.17      harris41  168: 
1.1       www       169: # ---------------------------------------------------------------- Print Header
1.15      harris41  170: 	$r->print(<<ENDHEADER);
1.1       www       171: <html>
                    172: <head>
1.2       harris41  173: <title>The LearningOnline Network With CAPA Directory Browser</title>
1.3       harris41  174: 
1.19      harris41  175: <script type="text/javascript">
1.7       harris41  176: $catalogmodefunctions
1.2       harris41  177: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                    178:     var options = "width=" + w + ",height=" + h + ",";
                    179:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                    180:     options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                    181:     var newWin = window.open(url, wdwName, options);
                    182:     newWin.focus();
                    183: }
1.16      harris41  184: function gothere(val) {
                    185:     window.location=val+'?acts='+document.forms.fileattr.acts.value;
                    186: }
1.14      harris41  187: </script>
1.3       harris41  188: 
1.1       www       189: </head>
                    190: <body bgcolor="#FFFFFF">
                    191: ENDHEADER
1.17      harris41  192: 
                    193: # - Evaluate actions from previous page (both cumulatively and chronologically)
1.16      harris41  194:         if ($ENV{'form.catalogmode'} eq 'groupimport') {
                    195: 	    my $acts=$ENV{'form.acts'};
                    196: 	    my @Acts=split(/b/,$acts);
                    197: 	    my %ahash;
                    198: 	    my %achash;
                    199: 	    my $ac=0;
1.17      harris41  200: 	    # some initial hashes for working with data
1.16      harris41  201: 	    map {
                    202: 		my ($state,$ref)=split(/a/);
                    203: 		$ahash{$ref}=$state;
                    204: 		$achash{$ref}=$ac;
                    205: 		$ac++;
                    206: 	    } (@Acts);
1.17      harris41  207: 	    # sorting through the actions and changing the tied database hash
1.16      harris41  208: 	    map {
                    209: 		my $key=$_;
                    210: 		if ($ahash{$key} eq '1') {
                    211: 		    $hash{'store_'.$hash{'pre_'.$key.'_link'}}=
                    212: 			$hash{'pre_'.$key.'_title'};
                    213: 		    $hash{'storectr_'.$hash{'pre_'.$key.'_link'}}=
                    214: 			$hash{'storectr'}+0;
                    215: 		    $hash{'storectr'}++;
                    216: 		}
                    217: 		if ($ahash{$key} eq '0') {
                    218: 		    if ($hash{'store_'.$hash{'pre_'.$key.'_link'}}) {
                    219: 			delete $hash{'store_'.$hash{'pre_'.$key.'_link'}};
                    220: 		    }
                    221: 		}
                    222: 	    } sort {$achash{$a}<=>$achash{$b}} (keys %ahash);
1.17      harris41  223: 	    # deleting the previously cached listing
1.16      harris41  224: 	    map {
                    225: 		if ($_ =~ /^pre_/ && $_ =~/link$/) {
                    226: 		    my $key = $_;
                    227: 		    $key =~ s/^pre_//;
                    228: 		    $key =~ s/_[^_]*$//;
                    229: 		    delete $hash{'pre_'.$key.'_title'};
                    230: 		    delete $hash{'pre_'.$key.'_link'};
                    231: 		}
                    232: 	    } keys %hash;
                    233: 	}
                    234: 	
1.17      harris41  235: # output title
                    236: 	$r->print('<h2><font color="#888888">The LearningOnline With CAPA '.
                    237: 		  'Network Directory Browser</font></h2>'."\n");
                    238: # get state of file attributes to be showing
1.6       harris41  239: 	if ($ENV{'form.attrs'} ne "") {
1.18      ng        240: 	    for (my $i=0; $i<=6; $i++) {
1.6       harris41  241: 		delete $hash{'display_attrs_'.$i};
                    242: 		if ($ENV{'form.attr'.$i} == 1) {
                    243: 		    $attrchk[$i] = "checked";
                    244: 		    $hash{'display_attrs_'.$i} = 1;
                    245: 		}
                    246: 	    }
                    247: 	} else {
1.18      ng        248: 	    for (my $i=0; $i<=6; $i++) {
1.6       harris41  249: 		$attrchk[$i] = "checked" if $hash{'display_attrs_'.$i} == 1;
                    250: 	    }
                    251: 	}
1.17      harris41  252: # output state of file attributes to be showing
1.15      harris41  253: 	$r->print(<<END);
1.17      harris41  254: <b><font color="#666666">Display file attributes</font></b><br />
                    255: <form method="post" name="fileattr" action="$uri"
                    256:  enctype="application/x-www-form-urlencoded">
1.1       www       257: <table border=0><tr>
1.16      harris41  258: <td><input type="checkbox" name="attr0" value="1" $attrchk[0] /> Size</td>
1.18      ng        259: <td><input type="checkbox" name="attr1" value="1" $attrchk[1] /> Last access</td>
                    260: <td><input type="checkbox" name="attr2" value="1" $attrchk[2] /> Last modified</td>
                    261: <td><input type="checkbox" name="attr6" value="1" $attrchk[6] /> All versions</td>
1.1       www       262: </tr><tr>
1.16      harris41  263: <td><input type="checkbox" name="attr3" value="1" $attrchk[3] /> Author</td>
                    264: <td><input type="checkbox" name="attr4" value="1" $attrchk[4] /> Keywords</td>
                    265: <td><input type="checkbox" name="attr5" value="1" $attrchk[5] /> Language</td>
1.18      ng        266: <td>&nbsp;</td>
1.1       www       267: </tr></table>
1.16      harris41  268: <input type="hidden" name="dirPointer" value="on" />
                    269: <input type="hidden" name="acts" value="" />
                    270: <input type="submit" name="attrs" value="Review" />&nbsp;
                    271: <input type="submit" name="attrs" value="Refresh" />
1.7       harris41  272: $closebutton
                    273: $groupimportbutton
1.1       www       274: </form>
                    275: END
                    276: 
1.17      harris41  277:     # output starting row to the indexed file/directory hierarchy
1.15      harris41  278:         my $titleclr="#ddffff";
                    279:         $r->print("<table border=0><tr><td bgcolor=#eeeeee>\n");
                    280: 	$r->print("<table border=0><tr>\n");
                    281: 	$r->print("<td $colspan bgcolor=$titleclr><b>Name</b></td>\n");
1.17      harris41  282: 	$r->print("<td bgcolor=$titleclr align=right><b>Size (bytes) ".
                    283: 		  "</b></td>\n") if ($hash{'display_attrs_0'} == 1);
                    284: 	$r->print("<td bgcolor=$titleclr><b>Last accessed</b></td>\n") 
                    285: 	    if ($hash{'display_attrs_1'} == 1);
                    286: 	$r->print("<td bgcolor=$titleclr><b>Last modified</b></td>\n")
                    287: 	    if ($hash{'display_attrs_2'} == 1);
                    288: 	$r->print("<td bgcolor=$titleclr><b>Author(s)</b></td>\n")
                    289: 	    if ($hash{'display_attrs_3'} == 1);
                    290: 	$r->print("<td bgcolor=$titleclr><b>Keywords</b></td>\n")
                    291: 	    if ($hash{'display_attrs_4'} == 1);
                    292: 	$r->print("<td bgcolor=$titleclr><b>Language</b></td>\n")
                    293: 	    if ($hash{'display_attrs_5'} == 1);
1.15      harris41  294: 	$r->print("</tr>");
1.5       harris41  295: 
1.17      harris41  296: 	# read in what directories have previously been set to "open"
1.4       harris41  297: 	map {
                    298: 	    if ($_ =~ /^diropen_status_/) {
                    299: 		my $key = $_;
                    300: 		$key =~ s/^diropen_status_//;
                    301: 		$dirs{$key} = $hash{$_};
                    302: 	    }
                    303: 	} keys %hash;
                    304: 
1.2       harris41  305: 	if ($ENV{'form.openuri'}) {  # take care of review and refresh options
                    306: 	    my $uri=$ENV{'form.openuri'};
1.4       harris41  307: 	    if (exists($hash{'diropen_status_'.$uri})) {
                    308: 		my $cursta = $hash{'diropen_status_'.$uri};
1.2       harris41  309: 		$dirs{$uri} = 'open';
1.4       harris41  310: 		$hash{'diropen_status_'.$uri} = 'open';
                    311: 		if ($cursta eq 'open') {
                    312: 		    $dirs{$uri} = 'closed';
                    313: 		    $hash{'diropen_status_'.$uri} = 'closed';
                    314: 		}
1.2       harris41  315: 	    } else {
1.4       harris41  316: 		$hash{'diropen_status_'.$uri} = 'open';
1.2       harris41  317: 		$dirs{$uri} = 'open';
                    318: 	    }
                    319: 	}
1.12      ng        320: 	
                    321: 	my $bredir = $ENV{'form.dirPointer'};
                    322: 	my $toplevel;
1.13      ng        323: 	my $indent = 0;
1.12      ng        324: 	$uri = $uri.'/' if $uri !~ /.*\/$/;
1.17      harris41  325: 
1.13      ng        326: 	if ($bredir ne "on") {
1.12      ng        327: 	    $hash{'top.level'} = $uri;
                    328: 	    $toplevel = $uri;
1.13      ng        329: 
                    330: 	} else {
                    331: 	    $toplevel = $hash{'top.level'};
                    332: 	}
1.17      harris41  333: 
                    334: 	# if not at top level, provide an uplink arrow
1.13      ng        335: 	if ($toplevel ne "/res/"){
                    336: 	    my (@uri_com) = split(/\//,$uri);
                    337: 	    pop @uri_com;
                    338: 	    my $upone = join('/',@uri_com);
                    339: 	    my @list = qw (0);
                    340: 	    &display_line ($r,'opened',$upone.'&viewOneUp',0,$upone,@list);
                    341: 	    $indent = 1;
1.12      ng        342: 	}
1.17      harris41  343: 
                    344: 	# recursively go through all the directories and output as appropriate
1.16      harris41  345: 	&scanDir ($r,$toplevel,$indent,\%hash);
1.12      ng        346: 	
1.17      harris41  347: 	# information useful for group import
1.8       harris41  348: 	$r->print("<form name='fnum'>");
                    349: 	$r->print("<input type='hidden' name='fnum' value='$fnum'></form>");
1.17      harris41  350: 
                    351: 	# end the tables
1.2       harris41  352: 	$r->print("</table>");
                    353: 	$r->print("</td></tr></table>");
1.17      harris41  354: 
                    355: 	# end the output and return
1.2       harris41  356: 	$r->print("</body></html>\n");
1.4       harris41  357: 	untie(%hash);
1.2       harris41  358:     } else {
1.17      harris41  359: 	$r->print('<html><head></head><body>Unable to tie hash to db '.
                    360: 		  'file</body></html>');
                    361: 	return OK;
1.2       harris41  362:     }
1.1       www       363:     return OK;
                    364: }
1.2       harris41  365: 
1.6       harris41  366: 
1.17      harris41  367: # ----------------------------------------------- recursive scan of a directory
1.2       harris41  368: sub scanDir {
1.16      harris41  369:     my ($r,$startdir,$indent,$hashref)=@_;
1.3       harris41  370:     my ($compuri,$curdir);
                    371:     my $dirptr=16384;
1.1       www       372:     $indent++;
                    373: 
1.2       harris41  374:     my %dupdirs = %dirs;
                    375:     my @list=&get_list($r,$startdir);
                    376:     foreach my $line (@list) {
1.5       harris41  377: 	my ($strip,$dom,$foo,$testdir,$foo)=split(/\&/,$line,5); 
1.4       harris41  378: 	next if $strip =~ /.*\.meta$/;
1.18      ng        379: 	my (@fileparts) = split(/\./,$strip);
                    380: 	if ($hash{'display_attrs_6'} != 1) {
                    381: 	    if (scalar(@fileparts) >= 3) {
                    382: 		my $fext = pop @fileparts;
                    383: 		my $ov = pop @fileparts;
                    384: 		my $fname = join ('.',@fileparts,$fext);
                    385: 		next if (grep /$fname/,@list and $ov =~ /\d+/);
                    386: 	    }
                    387: 	}
                    388: 
1.5       harris41  389: 	if ($dom eq "domain") {
1.17      harris41  390: 	    $compuri = join('',$strip,"/");  # dom list has /res/<domain name>
1.3       harris41  391: 	    $curdir = $compuri;
1.2       harris41  392: 	} else {
1.17      harris41  393: 	    # user, dir & file have name only, i.e., w/o path
                    394: 	    $compuri = join('',$startdir,$strip,"/");
1.3       harris41  395: 	    $curdir = $startdir;
1.2       harris41  396: 	}
1.11      ng        397: 	my $diropen = "closed";
1.5       harris41  398: 	if (($dirptr&$testdir) or ($dom =~ /^(domain|user)$/)) {
1.3       harris41  399: 	    while (my ($key,$val)= each %dupdirs) {
1.5       harris41  400: 		if ($key eq $compuri and $val eq "open") {
1.11      ng        401: 		    $diropen = "opened";
1.5       harris41  402: 		    delete $dupdirs{key},$dirs{$key};
                    403: 		}
1.3       harris41  404: 	    }
1.1       www       405: 	}
1.16      harris41  406: 	&display_line($r,$diropen,$line,$indent,$curdir,$hashref,@list);
1.11      ng        407: 	&scanDir ($r,$compuri,$indent) if $diropen eq "opened";
1.1       www       408:     }
                    409:     $indent--;
                    410: }
                    411: 
1.17      harris41  412: # --------------- get complete matched list based on the uri (returns an array)
1.1       www       413: sub get_list {
                    414:     my ($r,$uri)=@_;
                    415:     my @list;
1.2       harris41  416:     my $luri = $uri;
                    417:     $luri =~ s/\//_/g;
                    418: 
1.6       harris41  419:     if ($ENV{'form.attrs'} eq "Refresh") {
1.4       harris41  420: 	map {
                    421: 	    delete $hash{$_} if ($_ =~ /^dirlist_files_/);
                    422: 	    } keys %hash;
1.2       harris41  423:     }
                    424: 
1.4       harris41  425:     if ($hash{'dirlist_files'.$luri}) {
                    426: 	@list = split(/\n/,$hash{'dirlist_files_'.$luri});
1.1       www       427:     } else {
1.4       harris41  428: 	@list = &Apache::lonnet::dirlist($uri);
                    429: 	$hash{'dirlist_files_'.$luri} = join('\n',@list);
1.1       www       430:     }
                    431:     return @list=&match_ext($r,@list);
                    432: }
                    433: 
1.17      harris41  434: # -------------------- filters out files based on extensions (returns an array)
1.1       www       435: sub match_ext {
                    436:     my ($r,@packlist)=@_;
                    437:     my @trimlist;
                    438:     my $nextline;
                    439:     my @fileext;
                    440:     my $dirptr=16384;
                    441: 
                    442:     my $tabdir  = $r->dir_config('lonTabDir');
1.12      ng        443:     my $fn = $tabdir.'/filetypes.tab';
1.1       www       444:     if (-e $fn) {
                    445: 	my $FH=Apache::File->new($fn);
                    446: 	my @content=<$FH>;
1.2       harris41  447: 	foreach my $line (@content) {
1.1       www       448: 	    (my $ext,my $foo) = split /\s+/,$line;
                    449: 	    push @fileext,$ext;
                    450: 	}
                    451:     }
1.2       harris41  452:     foreach my $line (@packlist) {
                    453: 	chomp $line;
                    454: 	$line =~ s/^\/home\/httpd\/html//;
                    455: 	my @unpackline = split (/\&/,$line);
                    456: 	next if ($unpackline[0] eq ".");
                    457: 	next if ($unpackline[0] eq "..");
                    458: 	my @filecom = split (/\./,$unpackline[0]);
                    459: 	my $fext = pop(@filecom);
                    460: 	my $fnptr = $unpackline[3]&$dirptr;
                    461:  	if ($fnptr == 0 and $unpackline[3] ne "") {
                    462: 	    foreach my $nextline (@fileext) {
                    463: 		push @trimlist,$line if $nextline eq $fext;
1.1       www       464: 	    }
                    465: 	} else {
1.2       harris41  466: 	    push @trimlist,$line;
1.1       www       467: 	}
                    468:     }
1.4       harris41  469:     @trimlist = sort (@trimlist);
1.1       www       470:     return @trimlist;
                    471: }
                    472: 
1.17      harris41  473: # ------------------------------- displays one line in appropriate table format
1.1       www       474: sub display_line{
1.16      harris41  475:     my ($r,$diropen,$line,$indent,$startdir,$hashref,@list)=@_;
1.1       www       476:     my (@pathfn, $fndir, $fnptr);
                    477:     my $dirptr=16384;
                    478:     my $fileclr="#ffffe6";
1.10      harris41  479:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.1       www       480: 
                    481:     my @filecom = split (/\&/,$line);
                    482:     my @pathcom = split (/\//,$filecom[0]);
                    483:     my $listname = $pathcom[scalar(@pathcom)-1];
                    484:     my $fnptr = $filecom[3]&$dirptr;
1.4       harris41  485:     my $msg = 'View '.$filecom[0].' resources';
1.11      ng        486:     $msg = 'Close '.$filecom[0].' directory' if $diropen eq "opened";
1.1       www       487: 
                    488:     my $tabtag="</td>";
                    489:     my $i=0;
                    490: 
                    491:     while ($i<=5) {
1.17      harris41  492: 	$tabtag=join('',$tabtag,"<td bgcolor=",$fileclr,">&nbsp;</td>")
                    493: 	    if $hash{'display_attrs_'.$i} == 1;
1.1       www       494: 	$i++;
                    495:     }
1.17      harris41  496: 
                    497: # display uplink arrow
1.13      ng        498:     if ($filecom[1] eq "viewOneUp") {
                    499: 	$r->print("<tr>$extrafield");
                    500: 	$r->print("<td bgcolor=$fileclr valign=bottom>\n");
1.16      harris41  501: 	$r->print ('<form method="post" name="dirpathUP" action="'.$startdir.
                    502: 		   '/" '.
1.17      harris41  503: 		   'onSubmit="return rep_dirpath(\'UP\','.
                    504: 		   'document.forms.fileattr.acts.value)" '.
1.16      harris41  505: 		   'enctype="application/x-www-form-urlencoded"'.
                    506:                    '>'."\n");
1.17      harris41  507: 	$r->print ('<input type=hidden name=openuri value="'.
                    508: 		   $startdir.'">'."\n");
1.16      harris41  509: 	$r->print ('<input type="hidden" name="acts" value="">'."\n");
1.13      ng        510: 	$r->print ('<input src="'.$iconpath.'arrow_up.gif"');
1.17      harris41  511: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    512: 		   "\n");
1.13      ng        513: 	$r->print("Up $tabtag</tr></form>\n");
                    514: 	return OK;
                    515:     }
1.17      harris41  516: 
                    517: # display domain
1.1       www       518:     if ($filecom[1] eq "domain") {
1.17      harris41  519: 	$r->print ('<input type="hidden" name="dirPointer" value="on">'."\n")
                    520: 	    if ($ENV{'form.dirPointer'} eq "on");
1.7       harris41  521: 	$r->print("<tr>$extrafield");
1.1       www       522: 	$r->print("<td bgcolor=$fileclr valign=bottom>");
1.2       harris41  523: 	&begin_form ($r,$filecom[0].'/');
1.3       harris41  524: 	my $anchor = $filecom[0].'/';
                    525: 	$anchor =~ s/\///g;
1.13      ng        526: 	$r->print ('<a name="'.$anchor.'">');
1.16      harris41  527: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17      harris41  528: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.
                    529: 		   $diropen.'.gif"'); 
                    530: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    531: 		   "\n");
                    532: 	$r->print ('<a href="javascript:gothere(\''.$filecom[0].
                    533: 		   '/\')"><img src="'.$iconpath.'server.gif"');
                    534: 	$r->print (' border="0" /></a>'."\n");
1.1       www       535: 	$r->print("Domain - $listname $tabtag</tr></form>\n");
                    536: 	return OK;
1.17      harris41  537: 
                    538: # display user directory
1.1       www       539:     }
                    540:     if ($filecom[1] eq "user") {
1.7       harris41  541: 	$r->print("<tr>$extrafield");
1.13      ng        542: 	$r->print("<td bgcolor=$fileclr valign=bottom nowrap>\n");
1.2       harris41  543: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41  544: 	my $anchor = $curdir;
                    545: 	$anchor =~ s/\///g;
1.13      ng        546: 	&begin_form ($r,$curdir);
1.17      harris41  547: 	$r->print ('<a name="'.$anchor.'"><img src="'.$iconpath.
                    548: 		   'whitespace1.gif" border="0" />'."\n");
1.16      harris41  549: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17      harris41  550: 	$r->print ('<input src="'.$iconpath.'folder_pointer_'.$diropen.
                    551: 		   '.gif"'); 
                    552: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    553: 		   "\n");
                    554: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src='.
                    555: 		   $iconpath.'quill.gif border="0" name="'.$msg.
                    556: 		   '" height="22" /></a>');
1.13      ng        557: 	$r->print ($listname.$tabtag.'</tr></form>'."\n");
1.1       www       558: 	return OK;
                    559:     }
1.17      harris41  560: 
1.1       www       561: # display file
                    562:     if ($fnptr == 0 and $filecom[3] ne "") {
                    563: 	my @file_ext = split (/\./,$listname);
                    564: 	my $curfext = $file_ext[scalar(@file_ext)-1];
1.2       harris41  565: 	my $filelink = $startdir.$filecom[0];
1.8       harris41  566: 	$r->print("<tr><td nowrap valign='bottom' bgcolor=$fileclr>");
1.7       harris41  567: 	my $metafile = grep /^$filecom[0]\.meta\&/, @list;
                    568: 	my $title;
                    569:         if ($ENV{'form.catalogmode'} eq 'interactive') {
                    570: 	    $title=$listname;
1.8       harris41  571: 	    $title = &Apache::lonnet::metadata($filelink,'title')
                    572: 		if ($metafile == 1);
1.7       harris41  573: 	    $title=$listname unless $title;
                    574: 	    $r->print("<a href='javascript:select_data(\"",
                    575: 	              $title,'","',$filelink,"\")'>");
1.17      harris41  576: 	    $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
                    577: 		      "\n");
1.8       harris41  578: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
                    579: 	}
                    580:         elsif ($ENV{'form.catalogmode'} eq 'groupimport') {
                    581: 	    $title=$listname;
                    582: 	    $title = &Apache::lonnet::metadata($filelink,'title')
                    583: 		if ($metafile == 1);
                    584: 	    $title=$listname unless $title;
                    585: 	    $r->print("<form name='form$fnum'>\n");
                    586: 	    $r->print("<input type='checkbox' name='filelink"."' ".
1.16      harris41  587: 		      "value='$filelink' onClick='".
                    588: 		      "javascript:queue(\"form$fnum\")' ");
                    589: 	    if ($hash{'store_'.$filelink}) {
                    590: 		$r->print("checked");
                    591: 	    }
                    592: 	    $r->print(">\n");
1.8       harris41  593: 	    $r->print("<input type='hidden' name='title"."' ".
                    594: 		      "value='$title'>\n");
                    595: 	    $r->print("</form>\n");
                    596: 	    $r->print("</td><td valign='bottom' nowrap bgcolor=$fileclr>");
1.16      harris41  597: 	    $hash{"pre_${fnum}_link"}=$filelink;
                    598: 	    $hash{"pre_${fnum}_title"}=$title;
1.8       harris41  599:   	    $fnum++;
1.7       harris41  600: 	}
1.4       harris41  601: 
1.12      ng        602: 	if ($indent > 0 and $indent < 11) {
1.17      harris41  603: 	    $r->print("<img src=",$iconpath,"whitespace",$indent,
                    604: 		      ".gif border='0' />\n");
1.11      ng        605: 	} elsif ($indent >0) {
1.4       harris41  606: 	    my $ten = int($indent/10.);
                    607: 	    my $rem = $indent%10.0;
                    608: 	    my $count = 0;
                    609: 	    while ($count < $ten) {
1.17      harris41  610: 		$r->print("<img src=",$iconpath,
                    611: 			  "whitespace10.gif border='0' />\n");
1.1       www       612: 	    $count++;
1.4       harris41  613: 	    }
1.17      harris41  614: 	    $r->print("<img src=",$iconpath,"whitespace",$rem,
                    615: 		      ".gif border='0' />\n") if $rem > 0;
1.1       www       616: 	}
1.4       harris41  617: 
1.17      harris41  618: 	$r->print("<img src=$iconpath$curfext.gif border='0' />\n");
                    619: 	$r->print (" <a href=\"javascript:openWindow('".$filelink.
                    620: 		   "', 'metadatafile', '450', '500', 'no', 'yes')\";".
                    621: 		   " TARGET=_self>$listname</a> ");
                    622: 
                    623: 	$r->print (" (<a href=\"javascript:openWindow('".$filelink.
                    624: 		   ".meta', 'metadatafile', '400', '450', 'no', 'yes')\"; ".
                    625: 		   "TARGET=_self>metadata</a>) ") if ($metafile == 1);
1.2       harris41  626: 
1.7       harris41  627: 	$r->print("</td>\n");
1.17      harris41  628: 	$r->print("<td bgcolor=$fileclr align=right valign=bottom> ",
                    629: 		  $filecom[8]," </td>\n") 
1.11      ng        630: 	    if $hash{'display_attrs_0'} == 1;
1.17      harris41  631: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".
                    632: 		  (localtime($filecom[9]))." </td>\n") 
1.11      ng        633: 	    if $hash{'display_attrs_1'} == 1;
1.17      harris41  634: 	$r->print("<td bgcolor=$fileclr valign=bottom> ".
                    635: 		  (localtime($filecom[10]))." </td>\n") 
1.11      ng        636: 	    if $hash{'display_attrs_2'} == 1;
1.2       harris41  637: 
1.6       harris41  638: 	if ($hash{'display_attrs_3'} == 1) {
1.17      harris41  639: 	    my $author = &Apache::lonnet::metadata($filelink,'author')
                    640: 		if ($metafile == 1);
1.2       harris41  641: 	    $author = '&nbsp;' if (!$author);
1.17      harris41  642: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$author.
                    643: 		      " </td>\n");
1.2       harris41  644: 	}
1.6       harris41  645: 	if ($hash{'display_attrs_4'} == 1) {
1.17      harris41  646: 	    my $keywords = &Apache::lonnet::metadata($filelink,'keywords')
                    647: 		if ($metafile == 1);
1.2       harris41  648: 	    $keywords = '&nbsp;' if (!$keywords);
1.17      harris41  649: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$keywords.
                    650: 		      " </td>\n");
1.2       harris41  651: 	}
1.6       harris41  652: 	if ($hash{'display_attrs_5'} == 1) {
1.17      harris41  653: 	    my $lang = &Apache::lonnet::metadata($filelink,'language')
                    654: 		if ($metafile == 1);
1.2       harris41  655: 	    $lang = $language{$lang};
                    656: 	    $lang = '&nbsp;' if (!$lang);
1.17      harris41  657: 	    $r->print("<td bgcolor=$fileclr valign=bottom> ".$lang.
                    658: 		      " </td>\n");
1.2       harris41  659: 	}
1.1       www       660: 	$r->print("</tr>\n");
                    661:     }
1.17      harris41  662: 
1.2       harris41  663: # -- display directory
1.1       www       664:     if ($fnptr == $dirptr) {
                    665: 	my @file_ext = split (/\./,$listname);
                    666: 	my $curfext = $file_ext[scalar(@file_ext)-1];
1.2       harris41  667: 	my $curdir = $startdir.$filecom[0].'/';
1.3       harris41  668: 	my $anchor = $curdir;
                    669: 	$anchor =~ s/\///g;
1.7       harris41  670: 	$r->print("<tr>$extrafield<td bgcolor=$fileclr valign=bottom>");
1.2       harris41  671: 	&begin_form ($r,$curdir);
1.4       harris41  672: 	my $indentm1 = $indent-1;
1.11      ng        673: 	if ($indentm1 < 11 and $indentm1 > 0) {
1.17      harris41  674: 	    $r->print("<img src=",$iconpath,"whitespace",$indentm1,
                    675: 		      ".gif border='0' />\n");
1.4       harris41  676: 	} else {
                    677: 	    my $ten = int($indentm1/10.);
                    678: 	    my $rem = $indentm1%10.0;
                    679: 	    my $count = 0;
                    680: 	    while ($count < $ten) {
1.17      harris41  681: 		$r->print ("<img src=",$iconpath
                    682: 			   ,"whitespace10.gif border='0' />\n");
1.12      ng        683: 		$count++;
1.4       harris41  684: 	    }
1.17      harris41  685: 	    $r->print ("<img src=",$iconpath,"whitespace",$rem,
                    686: 		       ".gif border='0' />\n") if $rem > 0;
1.1       www       687: 	}
1.16      harris41  688: 	$r->print ('<input type="hidden" name="acts" value="">');
1.17      harris41  689: 	$r->print ('<a name="'.$anchor.'"><input src="'.$iconpath.
                    690: 		   'folder_pointer_'.$diropen.'.gif"');
                    691: 	$r->print (' name="'.$msg.'" height="22" type="image" border="0">'.
                    692: 		   "\n");
                    693: 	$r->print ('<a href="javascript:gothere(\''.$curdir.'\')"><img src="'.
                    694: 		   $iconpath.'folder_'.$diropen.'.gif" border="0" /></a>'.
                    695: 		   "\n");
1.13      ng        696: 	$r->print ("$listname$tabtag</tr></form>\n");
1.1       www       697:     }
1.2       harris41  698: 
1.1       www       699: }
                    700: 
1.14      harris41  701: # ------------------- prints the beginning of a form for directory or file link
1.1       www       702: sub begin_form {
                    703:     my ($r,$uri) = @_;
1.3       harris41  704:     my $anchor = $uri;
                    705:     $anchor =~ s/\///g;
1.17      harris41  706:     $r->print ('<form method="post" name="dirpath'.$dnum.'" action="'.$uri.
                    707: 	       '#'.$anchor.
                    708: 	       '" onSubmit="return rep_dirpath(\''.$dnum.'\''.
                    709: 	       ',document.forms.fileattr.acts.value)" '.
1.16      harris41  710: 	       'enctype="application/x-www-form-urlencoded">'."\n");
1.17      harris41  711:     $r->print ('<input type="hidden" name="openuri" value="'.$uri.'">'.
                    712: 	       "\n");
                    713:     $r->print ('<input type="hidden" name="dirPointer" value="on">'."\n");
1.16      harris41  714:     $dnum++;
1.17      harris41  715: }
                    716: 
                    717: # ----------- grab unprocessed CGI variables that may have been appended to URL
                    718: sub get_unprocessed_cgi {
                    719:     map {
                    720:        my ($name, $value) = split(/=/,$_);
                    721:        $value =~ tr/+/ /;
                    722:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                    723:        if ($name eq 'catalogmode' or $name eq 'launch' or $name eq 'acts') {
                    724:            $ENV{'form.'.$name}=$value;
                    725:        }
                    726:     } (split(/&/,$ENV{'QUERY_STRING'}));
                    727: }
                    728: 
                    729: # --------- settings whenever the user causes the indexer window to be launched
                    730: sub start_fresh_session {
                    731:     delete $hash{'mode_catalog'};
                    732:     map {
                    733: 	if ($_ =~ /^pre_/) {
                    734: 	    delete $hash{$_};
                    735: 	}
                    736: 	if ($_ =~ /^store/) {
                    737: 	    delete $hash{$_};
                    738: 	}
                    739:     } keys %hash;    
1.1       www       740: }
                    741: 
                    742: 1;
                    743: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>