use Tk;
use Tk::DialogBox;
use Tk::NoteBook;
use Tk::LabEntry;
use Tk::BrowseEntry;
use Tk::TopLevel;
# use Date::Manip;
use Text::ParseWords;
use Data::Dumper;
use strict; # Always!
$^W++; # Turn on warnings
require "common.pl";
my $config = { DSN => 'DBI:mysql:incontact',
MySQLunm => 'root',
MySQLpwd => '',
PWmaxtries => "3" };
my $state = { cur_user => '',
ImpFile => '',
ImpCnt => '',
ImpDs => ''};
my $DEBUG = 1;
my $mainwindow;
my $tli;
my $tlu;
my $dbh;
my (@map_fields, @file_fields, @user_fields, @dsources);
my $user;
####
if (! Exists($tli)) {
$tli = $mainwindow->Toplevel();
$tli->title("File Import");
$tli->LabEntry(-label => "File name",
-labelPack => [-side => "left", anchor => "w"],
-width => 40,
-textvariable => \$state->{ImpFile})->grid();
my $tli_ds = $tli->BrowseEntry(-label => "DataSource", -variable => \$state->{ImpDs} )->grid();
$tli_ds->focus;
my $SQL = "SELECT id, sourcename, sourcedesc from datasource;";
my $sth = $dbh->prepare( $SQL );
$sth->execute;
while (($id, $datasource, $ds_desc) = $sth->fetchrow_array) {
$tli_ds->insert('end', ($datasource." ".$ds_desc));
$rec->{$datasource} = ${ds_desc};
$dsources[$id] = $rec;
}
for ( $li = 0; $li < $imp_field_count; $li++ ) {
$tli->Label(-relief => 'sunken', width => 25, text => $file_fields[$li])->grid(
my $brb = $tli->BrowseEntry( -label => "", -variable => \$map_fields[$li]));
$brb->insert('end', @$ref);
}
$tli->Button(-text => 'Import', -command => \&doImport2)->grid(-pady => 5, -columnspan => 2);
} else {
$tli->deiconify();
$tli->raise();
}
debug("-doFileImport");
}
####
sub doManageUser {
my $uname;
my @listnames;
if ( ! Exists($tlu)) {
$tlu = $mainwindow->TopLevel();
$tlu->title("User Management");
my $lb = $tlu->BrowseEntry(-label => 'Username', -variable => \$uname,)->pack;
$lb->bind("", \&do_search);
$lb->focus;
my $SQL = "SELECT username FROM user;";
my $sth = $dbh->prepare( $SQL );
$sth->execute;
while (my $username = $sth->fetchrow_array) {
push @listnames, $username;
}
$sth->finish;
$lb->insert('end', @listnames);
$tlu->LabEntry(-label => "First Name",
-labelPack => [-side => "left", -anchor => "w"],
-width => 20,
-textvariable => \$user->{firstname})->pack(-side => "top",
-anchor => "ne");
$tlu->LabEntry(-label => "Last Name",
-labelPack => [-side => "left", -anchor => "w"],
-width => 20,
-textvariable => \$user->{lastname})->pack(-side => "top",
-anchor => "ne");
$tlu->LabEntry(-label => "Password",
-labelPack => [-side => "left", -anchor => "w"],
-width => 20,
-textvariable => \$user->{password})->pack(-side => "top",
-anchor => "ne");
$tlu->Button(-text => "Update",
-command => \&doUserUpdate)->pack(-side => "bottom");
} else {
$tlu->deiconify();
$tlu->raise();
}
}