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

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

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