File:  [LON-CAPA] / loncom / interface / lonindexer.pm
Revision 1.18: download - view: text, annotated - select for diffs
Tue Aug 14 14:13:03 2001 UTC (22 years, 9 months ago) by ng
Branches: MAIN
CVS tags: HEAD
add an option to suppress/show all versions of a file.

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

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