use IO::File;
use Fcntl qw(:seek);
+use SL::Auth;
use SL::DBUpgrade2;
use SL::DBUtils;
use SL::Iconv;
sub new {
$main::lxdebug->enter_sub();
- my ($type, $memfile, $login) = @_;
+ my ($type, $login) = @_;
+
my $self = {};
if ($login ne "") {
- local *MEMBER;
-
- $login =~ s|.*/||;
-
- &error("", "$memfile locked!") if (-f "${memfile}.LCK");
-
- open(MEMBER, "$memfile") or &error("", "$memfile : $!");
-
- while (<MEMBER>) {
- if (/^\[$login\]/) {
- while (<MEMBER>) {
- last if m/^\[/;
- next if m/^(#|\s)/;
-
- # remove comments
- s/\s#.*//g;
-
- # remove any trailing whitespace
- s/^\s*(.*?)\s*$/$1/;
-
- ($key, $value) = split(/=/, $_, 2);
-
- if (($key eq "stylesheet") && ($value eq "sql-ledger.css")) {
- $value = "lx-office-erp.css";
- }
-
- $self->{$key} = $value;
- }
-
- $self->{login} = $login;
-
- last;
- }
- }
- close MEMBER;
+ my %user_data = $main::auth->read_user($login);
+ map { $self->{$_} = $user_data{$_} } keys %user_data;
}
$main::lxdebug->leave_sub();
+
bless $self, $type;
}
sub login {
$main::lxdebug->enter_sub();
- my ($self, $form, $userspath) = @_;
+ my ($self, $form) = @_;
local *FH;
my $rc = -3;
if ($self->{login}) {
-
- if ($self->{password}) {
- if ($form->{hashed_password}) {
- $form->{password} = $form->{hashed_password};
- } else {
- $form->{password} = crypt($form->{password},
- substr($self->{login}, 0, 2));
- }
- if ($self->{password} ne $form->{password}) {
- $main::lxdebug->leave_sub();
- return -1;
- }
- }
-
- unless (-e "$userspath/$self->{login}.conf") {
- $self->create_config();
- }
-
- do "$userspath/$self->{login}.conf";
- $myconfig{dbpasswd} = unpack('u', $myconfig{dbpasswd});
+ my %myconfig = $main::auth->read_user($self->{login});
# check if database is down
my $dbh =
my ($dbversion) = $sth->fetchrow_array;
$sth->finish;
- # add login to employee table if it does not exist
- # no error check for employee table, ignore if it does not exist
- $query = qq|SELECT id FROM employee WHERE login = ?|;
- my ($login) = selectrow_query($form, $dbh, $query, $self->{login});
-
- if (!$login) {
- $query = qq|INSERT INTO employee (login, name, workphone, role)| .
- qq|VALUES (?, ?, ?, ?)|;
- my @values = ($self->{login}, $myconfig{name}, $myconfig{tel}, "user");
- do_query($form, $dbh, $query, @values);
- }
+ $self->create_employee_entry($form, $dbh, \%myconfig);
$self->create_schema_info_table($form, $dbh);
parse_dbupdate_controls($form, $myconfig{"dbdriver"});
map({ $form->{$_} = $myconfig{$_} }
- qw(dbname dbhost dbport dbdriver dbuser dbpasswd dbconnect));
+ qw(dbname dbhost dbport dbdriver dbuser dbpasswd dbconnect dateformat));
if (update_available($myconfig{"dbdriver"}, $dbversion) ||
update2_available($form, $controls)) {
$form->{"stylesheet"} = "lx-office-erp.css";
$form->{"title"} = $main::locale->text("Dataset upgrade");
$form->header();
- print($form->parse_html_template("dbupgrade/header"));
+ print $form->parse_html_template("dbupgrade/header");
$form->{dbupdate} = "db$myconfig{dbname}";
$form->{ $form->{dbupdate} } = 1;
if ($form->{"show_dbupdate_warning"}) {
- print($form->parse_html_template("dbupgrade/warning"));
+ print $form->parse_html_template("dbupgrade/warning");
exit(0);
}
# update the tables
- open(FH, ">$userspath/nologin") or die("$!");
+ open(FH, ">$main::userspath/nologin") or die("$!");
# required for Oracle
$form->{dbdefault} = $sid;
close(FH);
# remove lock file
- unlink("$userspath/nologin");
+ unlink("$main::userspath/nologin");
my $menufile =
$self->{"menustyle"} eq "v3" ? "menuv3.pl" :
$self->{"menustyle"} eq "neu" ? "menunew.pl" :
+ $self->{"menustyle"} eq "xml" ? "menuXML.pl" :
"menu.pl";
- print($form->parse_html_template("dbupgrade/footer",
- { "menufile" => $menufile }));
+ print $form->parse_html_template("dbupgrade/footer", { "menufile" => $menufile });
$rc = -2;
}
if (!defined($result)) {
- print($form->parse_html_template("dbupgrade/error",
- { "file" => $filename,
- "error" => $@ }));
+ print $form->parse_html_template("dbupgrade/error",
+ { "file" => $filename,
+ "error" => $@ });
exit(0);
} elsif (1 != $result) {
unlink("users/nologin") if (2 == $result);
sub dbsources_unused {
$main::lxdebug->enter_sub();
- my ($self, $form, $memfile) = @_;
-
- local *FH;
-
- my @dbexcl = ();
- my @dbsources = ();
-
- $form->error('File locked!') if (-f "${memfile}.LCK");
-
- # open members file
- open(FH, "$memfile") or $form->error("$memfile : $!");
-
- while (<FH>) {
- if (/^dbname=/) {
- my ($null, $item) = split(/=/);
- push @dbexcl, $item;
- }
- }
-
- close FH;
+ my ($self, $form) = @_;
$form->{only_acc_db} = 1;
- my @db = &dbsources("", $form);
- push @dbexcl, $form->{dbdefault};
+ my %members = $main::auth->read_all_users();
+ my %dbexcl = map { $_ => 1 } grep { $_ } map { $_->{dbname} } values %members;
- foreach $item (@db) {
- unless (grep /$item$/, @dbexcl) {
- push @dbsources, $item;
- }
- }
+ $dbexcl{$form->{dbdefault}} = 1;
+ $dbexcl{$main::auth->{DB_config}->{db}} = 1;
+
+ my @dbunused = grep { !$dbexcl{$_} } dbsources("", $form);
$main::lxdebug->leave_sub();
- return @dbsources;
+ return @dbunused;
}
sub dbneedsupdate {
my ($self, $form) = @_;
- my $members = Inifile->new($main::memberfile);
+ my %members = $main::auth->read_all_users();
my $controls = parse_dbupdate_controls($form, $form->{dbdriver});
my ($query, $sth, %dbs_needing_updates);
- foreach my $login (grep /[a-z]/, keys %{ $members }) {
- my $member = $members->{$login};
+ foreach my $login (grep /[a-z]/, keys %members) {
+ my $member = $members{$login};
map { $form->{$_} = $member->{$_} } qw(dbname dbuser dbpasswd dbhost dbport);
dbconnect_vars($form, $form->{dbname});
- $main::lxdebug->dump(0, "form", $form);
+
my $dbh = DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd});
next unless $dbh;
DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
or $form->dberror;
+ $dbh->do($form->{dboptions}) if ($form->{dboptions});
+
# check version
$query = qq|SELECT version FROM defaults|;
my ($version) = selectrow_query($form, $dbh, $query);
foreach my $upgradescript (@upgradescripts) {
my $a = $upgradescript;
- $a =~ s/^$form->{dbdriver}-upgrade-|\.(sql|pl)$//g;
+ $a =~ s/^\Q$form->{dbdriver}\E-upgrade-|\.(sql|pl)$//g;
my $file_type = $1;
my ($mindb, $maxdb) = split /-/, $a;
DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
or $form->dberror;
+ $dbh->do($form->{dboptions}) if ($form->{dboptions});
+
map({ $_->{"applied"} = 0; } @upgradescripts);
$self->create_schema_info_table($form, $dbh);
# apply upgrade
$main::lxdebug->message(DEBUG2, "Applying Update $control->{file}");
- print($form->parse_html_template("dbupgrade/upgrade_message2",
- $control));
+ print $form->parse_html_template("dbupgrade/upgrade_message2", $control);
if ($file_type eq "sql") {
$self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} .
$query = qq|SELECT tag FROM schema_info|;
$sth = $dbh->prepare($query);
- $sth->execute() || $form->dberror($query);
- while (($tag) = $sth->fetchrow_array()) {
- $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
+ if ($sth->execute()) {
+ while (($tag) = $sth->fetchrow_array()) {
+ $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
+ }
}
$sth->finish();
$dbh->disconnect();
return 0;
}
-sub create_config {
+sub save_member {
$main::lxdebug->enter_sub();
my ($self) = @_;
- local *CONF;
-
- @config = config_vars();
-
- my $userspath = $main::userspath;
-
- open(CONF, ">", "$userspath/$self->{login}.conf") || $self->error("$userspath/$self->{login}.conf : $!");
+ # format dbconnect and dboptions string
+ dbconnect_vars($self, $self->{dbname});
- # create the config file
- print CONF qq|# configuration file for $self->{login}
+ map { $self->{$_} =~ s/\r//g; } qw(address signature);
-\%myconfig = (
-|;
+ $main::auth->save_user($self->{login}, map { $_, $self->{$_} } config_vars());
- foreach my $key (sort @config) {
- $self->{$key} =~ s/\'/\\\'/g;
- print CONF qq| $key => '$self->{$key}',\n|;
+ my $dbh = DBI->connect($self->{dbconnect}, $self->{dbuser}, $self->{dbpasswd});
+ if ($dbh) {
+ $self->create_employee_entry($form, $dbh, $self);
+ $dbh->disconnect();
}
- print CONF qq|);\n\n|;
-
- close CONF;
-
$main::lxdebug->leave_sub();
}
-sub save_member {
+sub create_employee_entry {
$main::lxdebug->enter_sub();
- my ($self, $memberfile, $userspath) = @_;
-
- local (*FH, *CONF);
-
- my $newmember = 1;
-
- # format dbconnect and dboptions string
- &dbconnect_vars($self, $self->{dbname});
-
- $self->error('File locked!') if (-f "${memberfile}.LCK");
- open(FH, ">${memberfile}.LCK") or $self->error("${memberfile}.LCK : $!");
- close(FH);
-
- open(CONF, "+<$memberfile") or $self->error("$memberfile : $!");
-
- @config = <CONF>;
+ my $self = shift;
+ my $form = shift;
+ my $dbh = shift;
+ my $myconfig = shift;
- seek(CONF, 0, 0);
- truncate(CONF, 0);
+ # add login to employee table if it does not exist
+ # no error check for employee table, ignore if it does not exist
+ my ($login) = selectrow_query($form, $dbh, qq|SELECT id FROM employee WHERE login = ?|, $self->{login});
- while ($line = shift @config) {
- if ($line =~ /^\[$self->{login}\]/) {
- $newmember = 0;
- last;
- }
- print CONF $line;
- }
-
- # remove everything up to next login or EOF
- while ($line = shift @config) {
- last if ($line =~ /^\[/);
+ if (!$login) {
+ $query = qq|INSERT INTO employee (login, name, workphone, role) VALUES (?, ?, ?, ?)|;
+ do_query($form, $dbh, $query, ($self->{login}, $myconfig->{name}, $myconfig->{tel}, "user"));
}
- # this one is either the next login or EOF
- print CONF $line;
-
- while ($line = shift @config) {
- print CONF $line;
- }
-
- print CONF qq|[$self->{login}]\n|;
-
- if ((($self->{dbpasswd} ne $self->{old_dbpasswd}) || $newmember)
- && $self->{root}) {
- $self->{dbpasswd} = pack 'u', $self->{dbpasswd};
- chop $self->{dbpasswd};
- }
- if (defined($self->{new_password})) {
- if ($self->{new_password} ne $self->{old_password}) {
- $self->{password} = crypt $self->{new_password},
- substr($self->{login}, 0, 2)
- if $self->{new_password};
- }
- } else {
- if ($self->{password} ne $self->{old_password}) {
- $self->{password} = crypt $self->{password}, substr($self->{login}, 0, 2)
- if $self->{password};
- }
- }
-
- if ($self->{'root login'}) {
- @config = ("password");
- } else {
- @config = &config_vars;
- }
-
- # replace \r\n with \n
- map { $self->{$_} =~ s/\r\n/\\n/g } qw(address signature);
- foreach $key (sort @config) {
- print CONF qq|$key=$self->{$key}\n|;
- }
-
- print CONF "\n";
- close CONF;
- unlink "${memberfile}.LCK";
-
- # create conf file
- $self->create_config() unless $self->{'root login'};
-
$main::lxdebug->leave_sub();
}
printer role sid signature stylesheet tel templates vclimit angebote
bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen
taxnumber co_ustid duns menustyle template_format default_media
- default_printer_id copies show_form_details);
+ default_printer_id copies show_form_details favorites
+ pdonumber sdonumber);
$main::lxdebug->leave_sub();