sub orangeFile_explorer{
my ($hinweis) = @_;
# Dateien auslesen
my ($anzahl, %files) = orangeFile_datenlesen();
if($anzahl > 0){
$template{'file_anzahl'} = $anzahl." Dateien gefunden";
}else{
$template{'file_anzahl'} = "keine Dateien gefunden";
}
# Tree aufbauen #######################
our $SHIFTWIDTH = 4;
my $tree;
foreach(keys %files) { # jede Datenzeile
#print "Bearbeite Datei $_
\n";
$tree = process_data($_, $files{$_}, $tree); # verarbeiten und Baum hinzufuegen
}
my @js_tree; # Enthält den Baum in seiner Form für das JS
my $cnt=0; # Nur für debugging
sub process_data {
my($path, $row_data, $tree) = @_;
$tree = {'type' => 'dir'} unless $tree;
$path =~ s:^[\\/]::;
my($super, $sub) = split /[\/\\]/, $path, 2;
if($sub && $sub ne '') {
print "$path ist ein Verzeichnis
\n";
$tree->{'items'}->{$super} = process_data($sub, $row_data, {'dir' => 1});
} else {
print "$cnt. $path ist eine Datei
\n"; # HIER SIND ALLE DATEIEN!
$cnt++;
$tree->{'items'}->{$super} = {'file' => 1, 'data' => $row_data };
}
return $tree;
}
sub build_js_code {
my $tree = shift;
my $indent = shift || 1;
foreach my $key (sort {return $a cmp $b if $tree->{'items'}->{$a}->{'dir'}
&& $tree->{'items'}->{$b}->{'dir'};
return $a cmp $b if $tree->{'items'}->{$a}->{'file'}
&& $tree->{'items'}->{$b}->{'file'};
return $tree->{'items'}->{$a}->{'dir'} ? -1 : 1;}
keys %{ $tree->{'items'} } ) {
print "$key ist da
\n"; # HIER HABEN DIE UNTERVERZEICHNISSE NUR NOCH EINE DATEI.
if( $tree->{'items'}->{$key}->{'dir'} ) {
push @js_tree, ' ' x ($SHIFTWIDTH * $indent), "['", $key, "', null,\n"; # rekursiv
build_js_code( $tree->{'items'}->{$key}, $indent + 1);
push @js_tree, ' ' x ($SHIFTWIDTH * $indent), "],\n";
} else {
# Link zusammenbauen:
my $link = "?app=file&session_id=$template{'session_id'}&vertrag_id=$template{'vertrag_id'}&action=orangeFile_showfile&file_id=".$tree->{'items'}->{$key}->{'data'}->{'file_id'};
push @js_tree, ' ' x ($SHIFTWIDTH * $indent), "['", $key, "', '", $link , "'],\n"; # $key plus Link um Datei aufzurufen.
}
}
}
#######################################
# JavaScript im Dateihead für den Tree aufbauen
$template{'jshead'} .= "\n";
$template{'jshead'} .= "\n";
$template{'jshead'} .= "\n\n";
return("file", "explorer", $hinweis);
}