#!/opt/nokia/oss/perl/bin/perl -w --
eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
if 0;
## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr
+-ce -nibc -i=4 -pt=0 "-nsak=*"
use strict;
use warnings;
use Tk;
use Tk::Table;
use Tk::ProgressBar;
use Tk::Columns;
use Tk::WidgetDump;
my( $mw, $hist_win, $info_history_page, $navi_frame, $history_button,
+$list,
$hist_frame );
my( $first_button, $last_button, $back_button, $next_button );
my(
%date, %time, %rac_name, %alias, %profile_right,
%bearbeiter, %profile, %ext_dxt, %ticket_ref
);
my $history_file = \(
join '',
map {
( join ',', map { rand $_ } 1 .. 9 ) . "\n"
} 1 .. 50
);
my $last_id = 1;
my $shown_on_page = 25;
my $show_to = 25;
my $show_from = 1;
my $page = 1;
my $pages = 1;
$mw = MainWindow->new;
$mw->title( "RA-Management" );
my $mm = $mw->Frame(
-relief => 'ridge',
-bd => 2,
-borderwidth => 2,
-visual => "truecolor 2"
)->pack();
$history_button = $mm->Button(
-text => "History anzeigen",
-command => sub {
SUB_SHOW_HISTORY();
}
)->pack();
#~ $history_button ->invoke;## $history_button ->click;
$mw->update;
$mw->WidgetDump;
MainLoop;
sub SUB_SHOW_HISTORY {
&SUB_READ_HISTORY();
$pages = int( $last_id / $shown_on_page );
$hist_win = $mw->Toplevel();
$hist_win->geometry( '1000x760+0+0' );
$hist_win->minsize( 1000, 760 );
$hist_win->maxsize( 1000, 760 );
$hist_win->title( "Log History" );
$hist_win->Label( -text => "Änderungshistorie\n" )->pack();
$navi_frame = $hist_win->Frame( -borderwidth => 2, -relief => 'sun
+ken' )
->pack( -side => 'top', -fill => 'x' );
$info_history_page = $navi_frame->Label( -text => "Seite $page von
+ $pages" )
->grid( '-', '-', '-' );
$first_button = $navi_frame->Button(
-text => "<< Erste Seite",
-command => sub {
$page = 1;
$show_from = 1;
$show_to = $shown_on_page;
\&SUB_REFRESH_HIST();
}
)->grid(
$back_button = $navi_frame->Button(
-text => "< Zurück",
-command => sub {
$page = $page - 1;
$show_from = $show_from - $shown_on_page;
$show_to = $show_to - $shown_on_page;
\&SUB_REFRESH_HIST();
}
),
$next_button = $navi_frame->Button(
-text => "Vor >",
-command => sub {
$page = $page + 1;
$show_from = $show_from + $shown_on_page;
if( $show_to == 25 ) {
$show_to = $show_to + 1 + $shown_on_page;
} else {
$show_to = $show_to + $shown_on_page;
}
\&SUB_REFRESH_HIST();
}
),
$last_button = $navi_frame->Button(
-text => "Letzte Seite >>",
-command => sub {
$page = $pages;
$show_from = $pages * $shown_on_page;
$show_to = $last_id + 1;
\&SUB_REFRESH_HIST();
}
)
);
$hist_frame = $hist_win->Frame(
-borderwidth => 2,
-relief => 'sunken',
-height => 300
)->pack( -side => 'top', -fill => 'both' );
$list = $hist_frame->Columns( -height => 25 )
->pack( -expand => 1, -fill => 'both' );
my @columns_desc = (
"DB-ID", "Datum", "Zeit", "User Name",
"User-Alias", "Right", "NE-Name", "Ticket-Ref",
"Operator"
);
$list->ColumnButton( -text => "$columns_desc[0]", -width => 6 );
$list->ColumnButton( -text => "$columns_desc[1]", -width => 9 );
$list->ColumnButton( -text => "$columns_desc[2]", -width => 7 );
$list->ColumnButton( -text => "$columns_desc[3]", -width => 25 );
$list->ColumnButton( -text => "$columns_desc[4]", -width => 10 );
$list->ColumnButton( -text => "$columns_desc[5]", -width => 12 );
$list->ColumnButton( -text => "$columns_desc[6]", -width => 15 );
$list->ColumnButton( -text => "$columns_desc[7]", -width => 14 );
$list->ColumnButton( -text => "$columns_desc[8]", -width => 8 );
SUB_REFRESH_HIST();
theRealListHeight( $list, 25 );
my $button_ok = $hist_win->Button(
-text => 'OK',
-command => sub { $hist_win->destroy(); }
)->pack();
} ## end sub SUB_SHOW_HISTORY
sub SUB_REFRESH_HIST {
no warnings qw' uninitialized ';
if( $page == 1 ) {
$first_button->configure( -state => 'disabled' );
$back_button->configure( -state => 'disabled' );
$show_from = 1;
$show_to = 25;
} elsif( $page != 1 ) {
$first_button->configure( -state => 'normal' );
$back_button->configure( -state => 'normal' );
}
if( $page == $pages ) {
$last_button->configure( -state => 'disabled' );
$next_button->configure( -state => 'disabled' );
$show_to = $last_id;
} elsif( $page == $pages - 1 ) {
$last_button->configure( -state => 'normal' );
$next_button->configure( -state => 'normal' );
$show_from = $page * 25;
$show_to = $page * 25 + 25;
} elsif( $page != $pages ) {
$last_button->configure( -state => 'normal' );
$next_button->configure( -state => 'normal' );
}
$list->delete( 0, 'end' );
for( my $i = $show_from ; $i <= $show_to ; $i++ ) {
my $hist_db_id = sprintf "%06d", $i;
my $history_date = $date{$i};
$history_date =~ s/(\d{4})(\d{2})(\d{2})/$1-$2-$3/;
my $history_time = $time{$i};
$history_time =~ s/(\d{2})(\d{2})(\d{2})/$1:$2:$3/;
$list->insert(
'end', {
'DB-ID' => $hist_db_id,
'Datum' => $history_date,
'Zeit' => $history_time,
'User Name' => $rac_name{$i},
'User-Alias' => $alias{$i},
'Right' => $profile_right{$i},
'NE-Name' => $ext_dxt{$i},
'Ticket-Ref' => $ticket_ref{$i},
'Operator' => $bearbeiter{$i}
}
);
}
$list->pack( -side => 'left', -fill => 'both', -expand => 1 );
$info_history_page->configure( -text => "Seite $page von $pages" )
+;
$list->update;
} ## end sub SUB_REFRESH_HIST
sub SUB_READ_HISTORY {
if( !open( DATA, '+<', $history_file ) ) {
exit( 250 );
}
my $id = 1;
while( my $line = <DATA> ) {
chomp $line;
my @fields = split ",", $line;
$id = $fields[0];
if( defined $rac_name{$id} ) {
goto BEREITS_GELADEN;
}
$rac_name{$id} = $fields[1];
$alias{$id} = $fields[2];
if( $fields[3] =~ m/(NetAct(\d\d)|Unknown)/ ) {
my $prof_num = "";
if( defined $2 ) { $prof_num = $2 }
else { $profile_right{$id} = "Unknown"; }
$profile{$id} = $fields[3];
if( $prof_num eq "08" ) { $profile_right{$id} = "kein";
+ }
elsif( $prof_num eq "98" ) { $profile_right{$id} = "lesend
+"; }
elsif( $prof_num eq "20" ) { $profile_right{$id} = "schrei
+bend"; }
}
$bearbeiter{$id} = $fields[4];
$ticket_ref{$id} = $fields[5];
$date{$id} = $fields[6];
$time{$id} = $fields[7];
$ext_dxt{$id} = $fields[8];
BEREITS_GELADEN:
}
close DATA;
$last_id = $id;
} ## end sub SUB_READ_HISTORY
sub theRealListHeight {
my( $list, $height ) = @_;
use Data::Dump qw/ dd pp /;
foreach my $l_List ( $list->lists() ) {
dd "$l_List";
if( $l_List->isa( 'Tk::Listbox' ) ) {
$l_List->Tk::Listbox::configure( -height => $height );
}
}
} ## end sub theRealListHeight
|