1 #=====================================================================
 
   4 # Based on SQL-Ledger Version 2.1.9
 
   5 # Web http://www.lx-office.org
 
   7 #=====================================================================
 
   8 # SQL-Ledger Accounting
 
  11 #  Author: Dieter Simader
 
  12 #   Email: dsimader@sql-ledger.org
 
  13 #     Web: http://www.sql-ledger.org
 
  17 # This program is free software; you can redistribute it and/or modify
 
  18 # it under the terms of the GNU General Public License as published by
 
  19 # the Free Software Foundation; either version 2 of the License, or
 
  20 # (at your option) any later version.
 
  22 # This program is distributed in the hope that it will be useful,
 
  23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  25 # GNU General Public License for more details.
 
  26 # You should have received a copy of the GNU General Public License
 
  27 # along with this program; if not, write to the Free Software
 
  28 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
  29 #=====================================================================
 
  31 # user related functions
 
  33 #=====================================================================
 
  40   $main::lxdebug->enter_sub();
 
  42   my ($type, $memfile, $login) = @_;
 
  46     &error("", "$memfile locked!") if (-f "${memfile}.LCK");
 
  48     open(MEMBER, "$memfile") or &error("", "$memfile : $!");
 
  59           # remove any trailing whitespace
 
  62           ($key, $value) = split(/=/, $_, 2);
 
  64           if (($key eq "stylesheet") && ($value eq "sql-ledger.css")) {
 
  65             $value = "lx-office-erp.css";
 
  68           $self->{$key} = $value;
 
  71         $self->{login} = $login;
 
  79   $main::lxdebug->leave_sub();
 
  84   $main::lxdebug->enter_sub();
 
  89   # scan the locale directory and read in the LANGUAGE files
 
  90   opendir DIR, "locale";
 
  92   my @dir = grep !/(^\.\.?$|\..*)/, readdir DIR;
 
  94   foreach my $dir (@dir) {
 
  95     next unless open(FH, "locale/$dir/LANGUAGE");
 
  99     $cc{$dir} = "@language";
 
 104   $main::lxdebug->leave_sub();
 
 110   $main::lxdebug->enter_sub();
 
 112   my ($self, $form, $userspath) = @_;
 
 116   if ($self->{login}) {
 
 118     if ($self->{password}) {
 
 119       if ($form->{hashed_password}) {
 
 120         $form->{password} = $form->{hashed_password};
 
 122         $form->{password} = crypt($form->{password},
 
 123                                   substr($self->{login}, 0, 2));
 
 125       if ($self->{password} ne $form->{password}) {
 
 126         $main::lxdebug->leave_sub();
 
 131     unless (-e "$userspath/$self->{login}.conf") {
 
 132       $self->create_config("$userspath/$self->{login}.conf");
 
 135     do "$userspath/$self->{login}.conf";
 
 136     $myconfig{dbpasswd} = unpack 'u', $myconfig{dbpasswd};
 
 138     # check if database is down
 
 140       DBI->connect($myconfig{dbconnect}, $myconfig{dbuser},
 
 142       or $self->error(DBI::errstr);
 
 144     # we got a connection, check the version
 
 145     my $query = qq|SELECT version FROM defaults|;
 
 146     my $sth   = $dbh->prepare($query);
 
 147     $sth->execute || $form->dberror($query);
 
 149     my ($dbversion) = $sth->fetchrow_array;
 
 152     # add login to employee table if it does not exist
 
 153     # no error check for employee table, ignore if it does not exist
 
 154     $query = qq|SELECT e.id FROM employee e WHERE e.login = '$self->{login}'|;
 
 155     $sth   = $dbh->prepare($query);
 
 158     my ($login) = $sth->fetchrow_array;
 
 162       $query = qq|INSERT INTO employee (login, name, workphone, role)
 
 163                   VALUES ('$self->{login}', '$myconfig{name}',
 
 164                   '$myconfig{tel}', 'user')|;
 
 168     $self->create_schema_info_table($form, $dbh);
 
 175       parse_dbupdate_controls($form, $myconfig{"dbdriver"});
 
 177     map({ $form->{$_} = $myconfig{$_} }
 
 178         qw(dbname dbhost dbport dbdriver dbuser dbpasswd dbconnect));
 
 180     if (update_available($myconfig{"dbdriver"}, $dbversion) ||
 
 181         update2_available($form, $controls)) {
 
 183       $form->{"stylesheet"} = "lx-office-erp.css";
 
 184       $form->{"title"} = $main::locale->text("Dataset upgrade");
 
 186       print($form->parse_html_template("dbupgrade/header"));
 
 188       $form->{dbupdate} = "db$myconfig{dbname}";
 
 189       $form->{ $form->{dbupdate} } = 1;
 
 191       if ($form->{"show_dbupdate_warning"}) {
 
 192         print($form->parse_html_template("dbupgrade/warning"));
 
 197       open(FH, ">$userspath/nologin") or die("$!");
 
 199       # required for Oracle
 
 200       $form->{dbdefault} = $sid;
 
 202       # ignore HUP, QUIT in case the webserver times out
 
 203       $SIG{HUP}  = 'IGNORE';
 
 204       $SIG{QUIT} = 'IGNORE';
 
 206       $self->dbupdate($form);
 
 207       $self->dbupdate2($form, $controls);
 
 210       unlink("$userspath/nologin");
 
 212       print($form->parse_html_template("dbupgrade/footer"));
 
 219   $main::lxdebug->leave_sub();
 
 225   $main::lxdebug->enter_sub();
 
 227   my ($form, $db) = @_;
 
 230         'Pg' => { 'yy-mm-dd'   => 'set DateStyle to \'ISO\'',
 
 231                   'yyyy-mm-dd' => 'set DateStyle to \'ISO\'',
 
 232                   'mm/dd/yy'   => 'set DateStyle to \'SQL, US\'',
 
 233                   'mm-dd-yy'   => 'set DateStyle to \'POSTGRES, US\'',
 
 234                   'dd/mm/yy'   => 'set DateStyle to \'SQL, EUROPEAN\'',
 
 235                   'dd-mm-yy'   => 'set DateStyle to \'POSTGRES, EUROPEAN\'',
 
 236                   'dd.mm.yy'   => 'set DateStyle to \'GERMAN\''
 
 239           'yy-mm-dd'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'YY-MM-DD\'',
 
 240           'yyyy-mm-dd' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'YYYY-MM-DD\'',
 
 241           'mm/dd/yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'MM/DD/YY\'',
 
 242           'mm-dd-yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'MM-DD-YY\'',
 
 243           'dd/mm/yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD/MM/YY\'',
 
 244           'dd-mm-yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD-MM-YY\'',
 
 245           'dd.mm.yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD.MM.YY\'',
 
 248   $form->{dboptions} = $dboptions{ $form->{dbdriver} }{ $form->{dateformat} };
 
 250   if ($form->{dbdriver} eq 'Pg') {
 
 251     $form->{dbconnect} = "dbi:Pg:dbname=$db";
 
 254   if ($form->{dbdriver} eq 'Oracle') {
 
 255     $form->{dbconnect} = "dbi:Oracle:sid=$form->{sid}";
 
 258   if ($form->{dbhost}) {
 
 259     $form->{dbconnect} .= ";host=$form->{dbhost}";
 
 261   if ($form->{dbport}) {
 
 262     $form->{dbconnect} .= ";port=$form->{dbport}";
 
 265   $main::lxdebug->leave_sub();
 
 269   $main::lxdebug->enter_sub();
 
 271   my @drivers = DBI->available_drivers();
 
 273   $main::lxdebug->leave_sub();
 
 275   return (grep { /(Pg|Oracle)/ } @drivers);
 
 279   $main::lxdebug->enter_sub();
 
 281   my ($self, $form) = @_;
 
 286   $form->{dbdefault} = $form->{dbuser} unless $form->{dbdefault};
 
 287   $form->{sid} = $form->{dbdefault};
 
 288   &dbconnect_vars($form, $form->{dbdefault});
 
 291     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 294   if ($form->{dbdriver} eq 'Pg') {
 
 296     $query = qq|SELECT datname FROM pg_database WHERE NOT ((datname = 'template0') OR (datname = 'template1'))|;
 
 297     $sth   = $dbh->prepare($query);
 
 298     $sth->execute || $form->dberror($query);
 
 300     while (my ($db) = $sth->fetchrow_array) {
 
 302       if ($form->{only_acc_db}) {
 
 304         next if ($db =~ /^template/);
 
 306         &dbconnect_vars($form, $db);
 
 308           DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 311         $query = qq|SELECT p.tablename FROM pg_tables p
 
 312                     WHERE p.tablename = 'defaults'
 
 313                     AND p.tableowner = '$form->{dbuser}'|;
 
 314         my $sth = $dbh->prepare($query);
 
 315         $sth->execute || $form->dberror($query);
 
 317         if ($sth->fetchrow_array) {
 
 318           push @dbsources, $db;
 
 324       push @dbsources, $db;
 
 328   if ($form->{dbdriver} eq 'Oracle') {
 
 329     if ($form->{only_acc_db}) {
 
 330       $query = qq|SELECT o.owner FROM dba_objects o
 
 331                   WHERE o.object_name = 'DEFAULTS'
 
 332                   AND o.object_type = 'TABLE'|;
 
 334       $query = qq|SELECT username FROM dba_users|;
 
 337     $sth = $dbh->prepare($query);
 
 338     $sth->execute || $form->dberror($query);
 
 340     while (my ($db) = $sth->fetchrow_array) {
 
 341       push @dbsources, $db;
 
 348   $main::lxdebug->leave_sub();
 
 354   $main::lxdebug->enter_sub();
 
 356   my ($self, $form) = @_;
 
 358   $form->{sid} = $form->{dbdefault};
 
 359   &dbconnect_vars($form, $form->{dbdefault});
 
 361     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 365     'Pg'     => qq|CREATE DATABASE "$form->{db}"|,
 
 367       qq|CREATE USER "$form->{db}" DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP IDENTIFIED BY "$form->{db}"|
 
 374   push(@{$dboptions{"Pg"}}, "ENCODING = " . $dbh->quote($form->{"encoding"}))
 
 375     if ($form->{"encoding"});
 
 376   if ($form->{"dbdefault"}) {
 
 377     my $dbdefault = $form->{"dbdefault"};
 
 378     $dbdefault =~ s/[^a-zA-Z0-9_\-]//g;
 
 379     push(@{$dboptions{"Pg"}}, "TEMPLATE = $dbdefault");
 
 382   my $query = qq|$dbcreate{$form->{dbdriver}}|;
 
 383   $query .= " WITH " . join(" ", @{$dboptions{"Pg"}}) if (@{$dboptions{"Pg"}});
 
 385   $dbh->do($query) || $form->dberror($query);
 
 387   if ($form->{dbdriver} eq 'Oracle') {
 
 388     $query = qq|GRANT CONNECT,RESOURCE TO "$form->{db}"|;
 
 389     $dbh->do($query) || $form->dberror($query);
 
 393   # setup variables for the new database
 
 394   if ($form->{dbdriver} eq 'Oracle') {
 
 395     $form->{dbuser}   = $form->{db};
 
 396     $form->{dbpasswd} = $form->{db};
 
 399   &dbconnect_vars($form, $form->{db});
 
 401   $dbh = DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 405   my $filename = qq|sql/lx-office.sql|;
 
 406   $self->process_query($form, $dbh, $filename);
 
 409   ($filename) = split /_/, $form->{chart};
 
 411   $self->process_query($form, $dbh, "sql/${filename}-gifi.sql");
 
 413   # load chart of accounts
 
 414   $filename = qq|sql/$form->{chart}-chart.sql|;
 
 415   $self->process_query($form, $dbh, $filename);
 
 417   $query = "UPDATE defaults SET coa = " . $dbh->quote($form->{"chart"});
 
 418   $dbh->do($query) || $form->dberror($query);
 
 422   $main::lxdebug->leave_sub();
 
 425 # Process a Perl script which updates the database.
 
 426 # If the script returns 1 then the update was successful.
 
 427 # Return code "2" means "needs more interaction; remove
 
 428 # users/nologin and exit".
 
 429 # All other return codes are fatal errors.
 
 430 sub process_perl_script {
 
 431   $main::lxdebug->enter_sub();
 
 433   my ($self, $form, $dbh, $filename, $version) = @_;
 
 435   open(FH, "$filename") or $form->error("$filename : $!\n");
 
 436   my $contents = join("", <FH>);
 
 441   my %dbup_myconfig = ();
 
 442   map({ $dbup_myconfig{$_} = $form->{$_}; }
 
 443       qw(dbname dbuser dbpasswd dbhost dbport dbconnect));
 
 445   my $nls_file = $filename;
 
 446   $nls_file =~ s|.*/||;
 
 447   $nls_file =~ s|.pl$||;
 
 448   my $dbup_locale = Locale->new($main::language, $nls_file);
 
 450   my $result = eval($contents);
 
 457   if (!defined($result)) {
 
 458     print($form->parse_html_template("dbupgrade/error",
 
 459                                      { "file" => $filename,
 
 462   } elsif (1 != $result) {
 
 463     unlink("users/nologin") if (2 == $result);
 
 468     $dbh->do("UPDATE defaults SET version = " . $dbh->quote($version));
 
 472   $main::lxdebug->leave_sub();
 
 476   $main::lxdebug->enter_sub();
 
 478   my ($self, $form, $dbh, $filename, $version_or_control) = @_;
 
 480   #  return unless (-f $filename);
 
 482   open(FH, "$filename") or $form->error("$filename : $!\n");
 
 491     # Remove DOS and Unix style line endings.
 
 497     for (my $i = 0; $i < length($_); $i++) {
 
 498       my $char = substr($_, $i, 1);
 
 500       # Are we inside a string?
 
 502         if ($char eq $quote_chars[-1]) {
 
 508         if (($char eq "'") || ($char eq "\"")) {
 
 509           push(@quote_chars, $char);
 
 511         } elsif ($char eq ";") {
 
 513           # Query is complete. Send it.
 
 515           $sth = $dbh->prepare($query);
 
 516           if (!$sth->execute()) {
 
 517             my $errstr = $dbh->errstr;
 
 520             $form->dberror("The database update/creation did not succeed. The file ${filename} containing the following query failed:<br>${query}<br>" .
 
 521                            "The error message was: ${errstr}<br>" .
 
 522                            "All changes in that file have been reverted.");
 
 535   if (ref($version_or_control) eq "HASH") {
 
 536     $dbh->do("INSERT INTO schema_info (tag, login) VALUES (" .
 
 537              $dbh->quote($version_or_control->{"tag"}) . ", " .
 
 538              $dbh->quote($form->{"login"}) . ")");
 
 539   } elsif ($version_or_control) {
 
 540     $dbh->do("UPDATE defaults SET version = " .
 
 541              $dbh->quote($version_or_control));
 
 547   $main::lxdebug->leave_sub();
 
 551   $main::lxdebug->enter_sub();
 
 553   my ($self, $form) = @_;
 
 555   my %dbdelete = ('Pg'     => qq|DROP DATABASE "$form->{db}"|,
 
 556                   'Oracle' => qq|DROP USER $form->{db} CASCADE|);
 
 558   $form->{sid} = $form->{dbdefault};
 
 559   &dbconnect_vars($form, $form->{dbdefault});
 
 561     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 563   my $query = qq|$dbdelete{$form->{dbdriver}}|;
 
 564   $dbh->do($query) || $form->dberror($query);
 
 568   $main::lxdebug->leave_sub();
 
 571 sub dbsources_unused {
 
 572   $main::lxdebug->enter_sub();
 
 574   my ($self, $form, $memfile) = @_;
 
 579   $form->error('File locked!') if (-f "${memfile}.LCK");
 
 582   open(FH, "$memfile") or $form->error("$memfile : $!");
 
 586       my ($null, $item) = split(/=/);
 
 593   $form->{only_acc_db} = 1;
 
 594   my @db = &dbsources("", $form);
 
 596   push @dbexcl, $form->{dbdefault};
 
 598   foreach $item (@db) {
 
 599     unless (grep /$item$/, @dbexcl) {
 
 600       push @dbsources, $item;
 
 604   $main::lxdebug->leave_sub();
 
 610   $main::lxdebug->enter_sub();
 
 612   my ($self, $form) = @_;
 
 617   $form->{sid} = $form->{dbdefault};
 
 618   &dbconnect_vars($form, $form->{dbdefault});
 
 621     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 624   if ($form->{dbdriver} eq 'Pg') {
 
 626     $query = qq|SELECT d.datname FROM pg_database d, pg_user u
 
 627                 WHERE d.datdba = u.usesysid
 
 628                 AND u.usename = '$form->{dbuser}'|;
 
 629     my $sth = $dbh->prepare($query);
 
 630     $sth->execute || $form->dberror($query);
 
 632     while (my ($db) = $sth->fetchrow_array) {
 
 634       next if ($db =~ /^template/);
 
 636       &dbconnect_vars($form, $db);
 
 639         DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 642       $query = qq|SELECT t.tablename FROM pg_tables t
 
 643                   WHERE t.tablename = 'defaults'|;
 
 644       my $sth = $dbh->prepare($query);
 
 645       $sth->execute || $form->dberror($query);
 
 647       if ($sth->fetchrow_array) {
 
 648         $query = qq|SELECT version FROM defaults|;
 
 649         my $sth = $dbh->prepare($query);
 
 652         if (my ($version) = $sth->fetchrow_array) {
 
 653           $dbsources{$db} = $version;
 
 663   if ($form->{dbdriver} eq 'Oracle') {
 
 664     $query = qq|SELECT o.owner FROM dba_objects o
 
 665                 WHERE o.object_name = 'DEFAULTS'
 
 666                 AND o.object_type = 'TABLE'|;
 
 668     $sth = $dbh->prepare($query);
 
 669     $sth->execute || $form->dberror($query);
 
 671     while (my ($db) = $sth->fetchrow_array) {
 
 673       $form->{dbuser} = $db;
 
 674       &dbconnect_vars($form, $db);
 
 677         DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 680       $query = qq|SELECT version FROM defaults|;
 
 681       my $sth = $dbh->prepare($query);
 
 684       if (my ($version) = $sth->fetchrow_array) {
 
 685         $dbsources{$db} = $version;
 
 695   $main::lxdebug->leave_sub();
 
 702   $main::lxdebug->enter_sub(2);
 
 704   my (@v, $version, $i);
 
 706   @v = split(/\./, $_[0]);
 
 707   while (scalar(@v) < 4) {
 
 711   for ($i = 0; $i < 4; $i++) {
 
 716   $main::lxdebug->leave_sub(2);
 
 720 sub cmp_script_version {
 
 721   my ($a_from, $a_to, $b_from, $b_to);
 
 722   my ($i, $res_a, $res_b);
 
 723   my ($my_a, $my_b) = ($a, $b);
 
 725   $my_a =~ s/.*-upgrade-//;
 
 727   $my_b =~ s/.*-upgrade-//;
 
 729   ($my_a_from, $my_a_to) = split(/-/, $my_a);
 
 730   ($my_b_from, $my_b_to) = split(/-/, $my_b);
 
 732   $res_a = calc_version($my_a_from);
 
 733   $res_b = calc_version($my_b_from);
 
 735   if ($res_a == $res_b) {
 
 736     $res_a = calc_version($my_a_to);
 
 737     $res_b = calc_version($my_b_to);
 
 740   return $res_a <=> $res_b;
 
 744 sub update_available {
 
 745   my ($dbdriver, $cur_version) = @_;
 
 747   opendir SQLDIR, "sql/${dbdriver}-upgrade" or &error("", "sql/${dbdriver}-upgrade: $!");
 
 749     grep(/$form->{dbdriver}-upgrade-\Q$cur_version\E.*\.(sql|pl)$/, readdir(SQLDIR));
 
 752   return ($#upgradescripts > -1);
 
 755 sub create_schema_info_table {
 
 756   $main::lxdebug->enter_sub();
 
 758   my ($self, $form, $dbh) = @_;
 
 760   my $query = "SELECT tag FROM schema_info LIMIT 1";
 
 761   if (!$dbh->do($query)) {
 
 763       "CREATE TABLE schema_info (" .
 
 766       "  itime timestamp DEFAULT now(), " .
 
 767       "  PRIMARY KEY (tag))";
 
 768     $dbh->do($query) || $form->dberror($query);
 
 771   $main::lxdebug->leave_sub();
 
 775   $main::lxdebug->enter_sub();
 
 777   my ($self, $form) = @_;
 
 779   $form->{sid} = $form->{dbdefault};
 
 781   my @upgradescripts = ();
 
 785   if ($form->{dbupdate}) {
 
 787     # read update scripts into memory
 
 788     opendir SQLDIR, "sql/" . $form->{dbdriver} . "-upgrade" or &error("", "sql/" . $form->{dbdriver} . "-upgrade : $!");
 
 791       sort(cmp_script_version
 
 792            grep(/$form->{dbdriver}-upgrade-.*?\.(sql|pl)$/, readdir(SQLDIR)));
 
 797   foreach my $db (split / /, $form->{dbupdate}) {
 
 799     next unless $form->{$db};
 
 801     # strip db from dataset
 
 803     &dbconnect_vars($form, $db);
 
 806       DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 810     $query = qq|SELECT version FROM defaults|;
 
 811     my $sth = $dbh->prepare($query);
 
 813     # no error check, let it fall through
 
 816     my $version = $sth->fetchrow_array;
 
 819     next unless $version;
 
 822     $version = calc_version($version);
 
 825     foreach my $upgradescript (@upgradescripts) {
 
 826       my $a = $upgradescript;
 
 827       $a =~ s/^$form->{dbdriver}-upgrade-|\.(sql|pl)$//g;
 
 830       my ($mindb, $maxdb) = split /-/, $a;
 
 831       my $str_maxdb = $maxdb;
 
 833       $mindb = calc_version($mindb);
 
 834       $maxdb = calc_version($maxdb);
 
 837       next if ($version >= $maxdb);
 
 839       # if there is no upgrade script exit
 
 840       last if ($version < $mindb);
 
 843       $main::lxdebug->message(DEBUG2, "Applying Update $upgradescript");
 
 844       if ($file_type eq "sql") {
 
 845         $self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} . "-upgrade/$upgradescript", $str_maxdb);
 
 847         $self->process_perl_script($form, $dbh, "sql/" . $form->{"dbdriver"} . "-upgrade/$upgradescript", $str_maxdb);
 
 859   $main::lxdebug->leave_sub();
 
 865   $main::lxdebug->enter_sub();
 
 867   my ($self, $form, $controls) = @_;
 
 869   $form->{sid} = $form->{dbdefault};
 
 871   my @upgradescripts = ();
 
 872   my ($query, $sth, $tag);
 
 875   @upgradescripts = sort_dbupdate_controls($controls);
 
 877   foreach my $db (split / /, $form->{dbupdate}) {
 
 879     next unless $form->{$db};
 
 881     # strip db from dataset
 
 883     &dbconnect_vars($form, $db);
 
 886       DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 889     map({ $_->{"applied"} = 0; } @upgradescripts);
 
 891     $query = "SELECT tag FROM schema_info";
 
 892     $sth = $dbh->prepare($query);
 
 893     $sth->execute() || $form->dberror($query);
 
 894     while (($tag) = $sth->fetchrow_array()) {
 
 895       $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
 
 900     foreach (@upgradescripts) {
 
 901       if (!$_->{"applied"}) {
 
 907     next if ($all_applied);
 
 909     foreach my $control (@upgradescripts) {
 
 910       next if ($control->{"applied"});
 
 912       $control->{"file"} =~ /\.(sql|pl)$/;
 
 916       $main::lxdebug->message(DEBUG2, "Applying Update $control->{file}");
 
 917       print($form->parse_html_template("dbupgrade/upgrade_message2",
 
 920       if ($file_type eq "sql") {
 
 921         $self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} .
 
 922                              "-upgrade2/$control->{file}", $control);
 
 924         $self->process_perl_script($form, $dbh, "sql/" . $form->{"dbdriver"} .
 
 925                                    "-upgrade2/$control->{file}", $control);
 
 934   $main::lxdebug->leave_sub();
 
 939 sub update2_available {
 
 940   $main::lxdebug->enter_sub();
 
 942   my ($form, $controls) = @_;
 
 944   map({ $_->{"applied"} = 0; } values(%{$controls}));
 
 946   dbconnect_vars($form, $form->{"dbname"});
 
 949     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) ||
 
 952   my ($query, $tag, $sth);
 
 954   $query = "SELECT tag FROM schema_info";
 
 955   $sth = $dbh->prepare($query);
 
 956   $sth->execute() || $form->dberror($query);
 
 957   while (($tag) = $sth->fetchrow_array()) {
 
 958     $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
 
 963   map({ $main::lxdebug->leave_sub() and return 1 if (!$_->{"applied"}) }
 
 964       values(%{$controls}));
 
 966   $main::lxdebug->leave_sub();
 
 971   $main::lxdebug->enter_sub();
 
 973   my ($self, $filename) = @_;
 
 975   @config = &config_vars;
 
 977   open(CONF, ">$filename") or $self->error("$filename : $!");
 
 979   # create the config file
 
 980   print CONF qq|# configuration file for $self->{login}
 
 985   foreach $key (sort @config) {
 
 986     $self->{$key} =~ s/\'/\\\'/g;
 
 987     print CONF qq|  $key => '$self->{$key}',\n|;
 
 990   print CONF qq|);\n\n|;
 
 994   $main::lxdebug->leave_sub();
 
 998   $main::lxdebug->enter_sub();
 
1000   my ($self, $memberfile, $userspath) = @_;
 
1004   # format dbconnect and dboptions string
 
1005   &dbconnect_vars($self, $self->{dbname});
 
1007   $self->error('File locked!') if (-f "${memberfile}.LCK");
 
1008   open(FH, ">${memberfile}.LCK") or $self->error("${memberfile}.LCK : $!");
 
1011   open(CONF, "+<$memberfile") or $self->error("$memberfile : $!");
 
1018   while ($line = shift @config) {
 
1019     if ($line =~ /^\[$self->{login}\]/) {
 
1026   # remove everything up to next login or EOF
 
1027   while ($line = shift @config) {
 
1028     last if ($line =~ /^\[/);
 
1031   # this one is either the next login or EOF
 
1034   while ($line = shift @config) {
 
1038   print CONF qq|[$self->{login}]\n|;
 
1040   if ((($self->{dbpasswd} ne $self->{old_dbpasswd}) || $newmember)
 
1042     $self->{dbpasswd} = pack 'u', $self->{dbpasswd};
 
1043     chop $self->{dbpasswd};
 
1045   if (defined($self->{new_password})) {
 
1046     if ($self->{new_password} ne $self->{old_password}) {
 
1047       $self->{password} = crypt $self->{new_password},
 
1048         substr($self->{login}, 0, 2)
 
1049         if $self->{new_password};
 
1052     if ($self->{password} ne $self->{old_password}) {
 
1053       $self->{password} = crypt $self->{password}, substr($self->{login}, 0, 2)
 
1054         if $self->{password};
 
1058   if ($self->{'root login'}) {
 
1059     @config = ("password");
 
1061     @config = &config_vars;
 
1064   # replace \r\n with \n
 
1065   map { $self->{$_} =~ s/\r\n/\\n/g } qw(address signature);
 
1066   foreach $key (sort @config) {
 
1067     print CONF qq|$key=$self->{$key}\n|;
 
1072   unlink "${memberfile}.LCK";
 
1075   $self->create_config("$userspath/$self->{login}.conf")
 
1076     unless $self->{'root login'};
 
1078   $main::lxdebug->leave_sub();
 
1082   $main::lxdebug->enter_sub();
 
1084   my @conf = qw(acs address admin businessnumber charset company countrycode
 
1085     currency dateformat dbconnect dbdriver dbhost dbport dboptions
 
1086     dbname dbuser dbpasswd email fax name numberformat in_numberformat password
 
1087     printer role sid signature stylesheet tel templates vclimit angebote bestellungen rechnungen
 
1088     anfragen lieferantenbestellungen einkaufsrechnungen taxnumber co_ustid duns menustyle
 
1089     template_format copies show_form_details);
 
1091   $main::lxdebug->leave_sub();
 
1097   $main::lxdebug->enter_sub();
 
1099   my ($self, $msg) = @_;
 
1101   if ($ENV{HTTP_USER_AGENT}) {
 
1102     print qq|Content-Type: text/html
 
1104 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
 
1106 <body bgcolor=ffffff>
 
1108 <h2><font color=red>Error!</font></h2>
 
1113   die "Error: $msg\n";
 
1115   $main::lxdebug->leave_sub();