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) = @_;
 
 359     'Pg'     => qq|CREATE DATABASE "$form->{db}"|,
 
 361       qq|CREATE USER "$form->{db}" DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP IDENTIFIED BY "$form->{db}"|
 
 364   $dbcreate{Pg} .= " WITH ENCODING = '$form->{encoding}'" if $form->{encoding};
 
 366   $form->{sid} = $form->{dbdefault};
 
 367   &dbconnect_vars($form, $form->{dbdefault});
 
 369     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 371   my $query = qq|$dbcreate{$form->{dbdriver}}|;
 
 372   $dbh->do($query) || $form->dberror($query);
 
 374   if ($form->{dbdriver} eq 'Oracle') {
 
 375     $query = qq|GRANT CONNECT,RESOURCE TO "$form->{db}"|;
 
 376     $dbh->do($query) || $form->dberror($query);
 
 380   # setup variables for the new database
 
 381   if ($form->{dbdriver} eq 'Oracle') {
 
 382     $form->{dbuser}   = $form->{db};
 
 383     $form->{dbpasswd} = $form->{db};
 
 386   &dbconnect_vars($form, $form->{db});
 
 388   $dbh = DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 392   my $filename = qq|sql/lx-office.sql|;
 
 393   $self->process_query($form, $dbh, $filename);
 
 396   ($filename) = split /_/, $form->{chart};
 
 398   $self->process_query($form, $dbh, "sql/${filename}-gifi.sql");
 
 400   # load chart of accounts
 
 401   $filename = qq|sql/$form->{chart}-chart.sql|;
 
 402   $self->process_query($form, $dbh, $filename);
 
 404   $query = "UPDATE defaults SET coa = " . $dbh->quote($form->{"chart"});
 
 405   $dbh->do($query) || $form->dberror($query);
 
 409   $main::lxdebug->leave_sub();
 
 412 # Process a Perl script which updates the database.
 
 413 # If the script returns 1 then the update was successful.
 
 414 # Return code "2" means "needs more interaction; remove
 
 415 # users/nologin and exit".
 
 416 # All other return codes are fatal errors.
 
 417 sub process_perl_script {
 
 418   $main::lxdebug->enter_sub();
 
 420   my ($self, $form, $dbh, $filename, $version) = @_;
 
 422   open(FH, "$filename") or $form->error("$filename : $!\n");
 
 423   my $contents = join("", <FH>);
 
 428   my %dbup_myconfig = ();
 
 429   map({ $dbup_myconfig{$_} = $form->{$_}; }
 
 430       qw(dbname dbuser dbpasswd dbhost dbport dbconnect));
 
 432   my $nls_file = $filename;
 
 433   $nls_file =~ s|.*/||;
 
 434   $nls_file =~ s|.pl$||;
 
 435   my $dbup_locale = Locale->new($main::language, $nls_file);
 
 437   my $result = eval($contents);
 
 444   if (!defined($result)) {
 
 445     print($form->parse_html_template("dbupgrade/error",
 
 446                                      { "file" => $filename,
 
 449   } elsif (1 != $result) {
 
 450     unlink("users/nologin") if (2 == $result);
 
 455     $dbh->do("UPDATE defaults SET version = " . $dbh->quote($version));
 
 459   $main::lxdebug->leave_sub();
 
 463   $main::lxdebug->enter_sub();
 
 465   my ($self, $form, $dbh, $filename, $version_or_control) = @_;
 
 467   #  return unless (-f $filename);
 
 469   open(FH, "$filename") or $form->error("$filename : $!\n");
 
 478     # Remove DOS and Unix style line endings.
 
 484     for (my $i = 0; $i < length($_); $i++) {
 
 485       my $char = substr($_, $i, 1);
 
 487       # Are we inside a string?
 
 489         if ($char eq $quote_chars[-1]) {
 
 495         if (($char eq "'") || ($char eq "\"")) {
 
 496           push(@quote_chars, $char);
 
 498         } elsif ($char eq ";") {
 
 500           # Query is complete. Send it.
 
 502           $sth = $dbh->prepare($query);
 
 503           if (!$sth->execute()) {
 
 504             my $errstr = $dbh->errstr;
 
 507             $form->dberror("The database update/creation did not succeed. The file ${filename} containing the following query failed:<br>${query}<br>" .
 
 508                            "The error message was: ${errstr}<br>" .
 
 509                            "All changes in that file have been reverted.");
 
 522   if (ref($version_or_control) eq "HASH") {
 
 523     $dbh->do("INSERT INTO schema_info (tag, login) VALUES (" .
 
 524              $dbh->quote($version_or_control->{"tag"}) . ", " .
 
 525              $dbh->quote($form->{"login"}) . ")");
 
 526   } elsif ($version_or_control) {
 
 527     $dbh->do("UPDATE defaults SET version = " . $dbh->quote($version));
 
 533   $main::lxdebug->leave_sub();
 
 537   $main::lxdebug->enter_sub();
 
 539   my ($self, $form) = @_;
 
 541   my %dbdelete = ('Pg'     => qq|DROP DATABASE "$form->{db}"|,
 
 542                   'Oracle' => qq|DROP USER $form->{db} CASCADE|);
 
 544   $form->{sid} = $form->{dbdefault};
 
 545   &dbconnect_vars($form, $form->{dbdefault});
 
 547     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 549   my $query = qq|$dbdelete{$form->{dbdriver}}|;
 
 550   $dbh->do($query) || $form->dberror($query);
 
 554   $main::lxdebug->leave_sub();
 
 557 sub dbsources_unused {
 
 558   $main::lxdebug->enter_sub();
 
 560   my ($self, $form, $memfile) = @_;
 
 565   $form->error('File locked!') if (-f "${memfile}.LCK");
 
 568   open(FH, "$memfile") or $form->error("$memfile : $!");
 
 572       my ($null, $item) = split(/=/);
 
 579   $form->{only_acc_db} = 1;
 
 580   my @db = &dbsources("", $form);
 
 582   push @dbexcl, $form->{dbdefault};
 
 584   foreach $item (@db) {
 
 585     unless (grep /$item$/, @dbexcl) {
 
 586       push @dbsources, $item;
 
 590   $main::lxdebug->leave_sub();
 
 596   $main::lxdebug->enter_sub();
 
 598   my ($self, $form) = @_;
 
 603   $form->{sid} = $form->{dbdefault};
 
 604   &dbconnect_vars($form, $form->{dbdefault});
 
 607     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 610   if ($form->{dbdriver} eq 'Pg') {
 
 612     $query = qq|SELECT d.datname FROM pg_database d, pg_user u
 
 613                 WHERE d.datdba = u.usesysid
 
 614                 AND u.usename = '$form->{dbuser}'|;
 
 615     my $sth = $dbh->prepare($query);
 
 616     $sth->execute || $form->dberror($query);
 
 618     while (my ($db) = $sth->fetchrow_array) {
 
 620       next if ($db =~ /^template/);
 
 622       &dbconnect_vars($form, $db);
 
 625         DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 628       $query = qq|SELECT t.tablename FROM pg_tables t
 
 629                   WHERE t.tablename = 'defaults'|;
 
 630       my $sth = $dbh->prepare($query);
 
 631       $sth->execute || $form->dberror($query);
 
 633       if ($sth->fetchrow_array) {
 
 634         $query = qq|SELECT version FROM defaults|;
 
 635         my $sth = $dbh->prepare($query);
 
 638         if (my ($version) = $sth->fetchrow_array) {
 
 639           $dbsources{$db} = $version;
 
 649   if ($form->{dbdriver} eq 'Oracle') {
 
 650     $query = qq|SELECT o.owner FROM dba_objects o
 
 651                 WHERE o.object_name = 'DEFAULTS'
 
 652                 AND o.object_type = 'TABLE'|;
 
 654     $sth = $dbh->prepare($query);
 
 655     $sth->execute || $form->dberror($query);
 
 657     while (my ($db) = $sth->fetchrow_array) {
 
 659       $form->{dbuser} = $db;
 
 660       &dbconnect_vars($form, $db);
 
 663         DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 666       $query = qq|SELECT version FROM defaults|;
 
 667       my $sth = $dbh->prepare($query);
 
 670       if (my ($version) = $sth->fetchrow_array) {
 
 671         $dbsources{$db} = $version;
 
 681   $main::lxdebug->leave_sub();
 
 688   $main::lxdebug->enter_sub(2);
 
 690   my (@v, $version, $i);
 
 692   @v = split(/\./, $_[0]);
 
 693   while (scalar(@v) < 4) {
 
 697   for ($i = 0; $i < 4; $i++) {
 
 702   $main::lxdebug->leave_sub(2);
 
 706 sub cmp_script_version {
 
 707   my ($a_from, $a_to, $b_from, $b_to);
 
 708   my ($i, $res_a, $res_b);
 
 709   my ($my_a, $my_b) = ($a, $b);
 
 711   $my_a =~ s/.*-upgrade-//;
 
 713   $my_b =~ s/.*-upgrade-//;
 
 715   ($my_a_from, $my_a_to) = split(/-/, $my_a);
 
 716   ($my_b_from, $my_b_to) = split(/-/, $my_b);
 
 718   $res_a = calc_version($my_a_from);
 
 719   $res_b = calc_version($my_b_from);
 
 721   if ($res_a == $res_b) {
 
 722     $res_a = calc_version($my_a_to);
 
 723     $res_b = calc_version($my_b_to);
 
 726   return $res_a <=> $res_b;
 
 730 sub update_available {
 
 731   my ($dbdriver, $cur_version) = @_;
 
 733   opendir SQLDIR, "sql/${dbdriver}-upgrade" or &error("", "sql/${dbdriver}-upgrade: $!");
 
 735     grep(/$form->{dbdriver}-upgrade-\Q$cur_version\E.*\.(sql|pl)$/, readdir(SQLDIR));
 
 738   return ($#upgradescripts > -1);
 
 741 sub create_schema_info_table {
 
 742   $main::lxdebug->enter_sub();
 
 744   my ($self, $form, $dbh) = @_;
 
 746   my $query = "SELECT tag FROM schema_info LIMIT 1";
 
 747   if (!$dbh->do($query)) {
 
 749       "CREATE TABLE schema_info (" .
 
 752       "  itime timestamp DEFAULT now(), " .
 
 753       "  PRIMARY KEY (tag))";
 
 754     $dbh->do($query) || $form->dberror($query);
 
 757   $main::lxdebug->leave_sub();
 
 761   $main::lxdebug->enter_sub();
 
 763   my ($self, $form) = @_;
 
 765   $form->{sid} = $form->{dbdefault};
 
 767   my @upgradescripts = ();
 
 771   if ($form->{dbupdate}) {
 
 773     # read update scripts into memory
 
 774     opendir SQLDIR, "sql/" . $form->{dbdriver} . "-upgrade" or &error("", "sql/" . $form->{dbdriver} . "-upgrade : $!");
 
 777       sort(cmp_script_version
 
 778            grep(/$form->{dbdriver}-upgrade-.*?\.(sql|pl)$/, readdir(SQLDIR)));
 
 783   foreach my $db (split / /, $form->{dbupdate}) {
 
 785     next unless $form->{$db};
 
 787     # strip db from dataset
 
 789     &dbconnect_vars($form, $db);
 
 792       DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 796     $query = qq|SELECT version FROM defaults|;
 
 797     my $sth = $dbh->prepare($query);
 
 799     # no error check, let it fall through
 
 802     my $version = $sth->fetchrow_array;
 
 805     next unless $version;
 
 808     $version = calc_version($version);
 
 811     foreach my $upgradescript (@upgradescripts) {
 
 812       my $a = $upgradescript;
 
 813       $a =~ s/^$form->{dbdriver}-upgrade-|\.(sql|pl)$//g;
 
 816       my ($mindb, $maxdb) = split /-/, $a;
 
 817       my $str_maxdb = $maxdb;
 
 819       $mindb = calc_version($mindb);
 
 820       $maxdb = calc_version($maxdb);
 
 823       next if ($version >= $maxdb);
 
 825       # if there is no upgrade script exit
 
 826       last if ($version < $mindb);
 
 829       $main::lxdebug->message(DEBUG2, "Applying Update $upgradescript");
 
 830       if ($file_type eq "sql") {
 
 831         $self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} . "-upgrade/$upgradescript", $str_maxdb);
 
 833         $self->process_perl_script($form, $dbh, "sql/" . $form->{"dbdriver"} . "-upgrade/$upgradescript", $str_maxdb);
 
 845   $main::lxdebug->leave_sub();
 
 851   $main::lxdebug->enter_sub();
 
 853   my ($self, $form, $controls) = @_;
 
 855   $form->{sid} = $form->{dbdefault};
 
 857   my @upgradescripts = ();
 
 858   my ($query, $sth, $tag);
 
 861   @upgradescripts = sort_dbupdate_controls($controls);
 
 863   foreach my $db (split / /, $form->{dbupdate}) {
 
 865     next unless $form->{$db};
 
 867     # strip db from dataset
 
 869     &dbconnect_vars($form, $db);
 
 872       DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 875     map({ $_->{"applied"} = 0; } @upgradescripts);
 
 877     $query = "SELECT tag FROM schema_info";
 
 878     $sth = $dbh->prepare($query);
 
 879     $sth->execute() || $form->dberror($query);
 
 880     while (($tag) = $sth->fetchrow_array()) {
 
 881       $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
 
 886     foreach (@upgradescripts) {
 
 887       if (!$_->{"applied"}) {
 
 893     next if ($all_applied);
 
 895     foreach my $control (@upgradescripts) {
 
 896       next if ($control->{"applied"});
 
 898       $control->{"file"} =~ /\.(sql|pl)$/;
 
 902       $main::lxdebug->message(DEBUG2, "Applying Update $control->{file}");
 
 903       print($form->parse_html_template("dbupgrade/upgrade_message2",
 
 906       if ($file_type eq "sql") {
 
 907         $self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} .
 
 908                              "-upgrade2/$control->{file}", $control);
 
 910         $self->process_perl_script($form, $dbh, "sql/" . $form->{"dbdriver"} .
 
 911                                    "-upgrade2/$control->{file}", $control);
 
 920   $main::lxdebug->leave_sub();
 
 925 sub update2_available {
 
 926   $main::lxdebug->enter_sub();
 
 928   my ($form, $controls) = @_;
 
 930   map({ $_->{"applied"} = 0; } values(%{$controls}));
 
 932   dbconnect_vars($form, $form->{"dbname"});
 
 935     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) ||
 
 938   my ($query, $tag, $sth);
 
 940   $query = "SELECT tag FROM schema_info";
 
 941   $sth = $dbh->prepare($query);
 
 942   $sth->execute() || $form->dberror($query);
 
 943   while (($tag) = $sth->fetchrow_array()) {
 
 944     $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
 
 949   map({ $main::lxdebug->leave_sub() and return 1 if (!$_->{"applied"}) }
 
 950       values(%{$controls}));
 
 952   $main::lxdebug->leave_sub();
 
 957   $main::lxdebug->enter_sub();
 
 959   my ($self, $filename) = @_;
 
 961   @config = &config_vars;
 
 963   open(CONF, ">$filename") or $self->error("$filename : $!");
 
 965   # create the config file
 
 966   print CONF qq|# configuration file for $self->{login}
 
 971   foreach $key (sort @config) {
 
 972     $self->{$key} =~ s/\'/\\\'/g;
 
 973     print CONF qq|  $key => '$self->{$key}',\n|;
 
 976   print CONF qq|);\n\n|;
 
 980   $main::lxdebug->leave_sub();
 
 984   $main::lxdebug->enter_sub();
 
 986   my ($self, $memberfile, $userspath) = @_;
 
 990   # format dbconnect and dboptions string
 
 991   &dbconnect_vars($self, $self->{dbname});
 
 993   $self->error('File locked!') if (-f "${memberfile}.LCK");
 
 994   open(FH, ">${memberfile}.LCK") or $self->error("${memberfile}.LCK : $!");
 
 997   open(CONF, "+<$memberfile") or $self->error("$memberfile : $!");
 
1004   while ($line = shift @config) {
 
1005     if ($line =~ /^\[$self->{login}\]/) {
 
1012   # remove everything up to next login or EOF
 
1013   while ($line = shift @config) {
 
1014     last if ($line =~ /^\[/);
 
1017   # this one is either the next login or EOF
 
1020   while ($line = shift @config) {
 
1024   print CONF qq|[$self->{login}]\n|;
 
1026   if ((($self->{dbpasswd} ne $self->{old_dbpasswd}) || $newmember)
 
1028     $self->{dbpasswd} = pack 'u', $self->{dbpasswd};
 
1029     chop $self->{dbpasswd};
 
1031   if (defined($self->{new_password})) {
 
1032     if ($self->{new_password} ne $self->{old_password}) {
 
1033       $self->{password} = crypt $self->{new_password},
 
1034         substr($self->{login}, 0, 2)
 
1035         if $self->{new_password};
 
1038     if ($self->{password} ne $self->{old_password}) {
 
1039       $self->{password} = crypt $self->{password}, substr($self->{login}, 0, 2)
 
1040         if $self->{password};
 
1044   if ($self->{'root login'}) {
 
1045     @config = ("password");
 
1047     @config = &config_vars;
 
1050   # replace \r\n with \n
 
1051   map { $self->{$_} =~ s/\r\n/\\n/g } qw(address signature);
 
1052   foreach $key (sort @config) {
 
1053     print CONF qq|$key=$self->{$key}\n|;
 
1058   unlink "${memberfile}.LCK";
 
1061   $self->create_config("$userspath/$self->{login}.conf")
 
1062     unless $self->{'root login'};
 
1064   $main::lxdebug->leave_sub();
 
1068   $main::lxdebug->enter_sub();
 
1070   my @conf = qw(acs address admin businessnumber charset company countrycode
 
1071     currency dateformat dbconnect dbdriver dbhost dbport dboptions
 
1072     dbname dbuser dbpasswd email fax name numberformat in_numberformat password
 
1073     printer role sid signature stylesheet tel templates vclimit angebote bestellungen rechnungen
 
1074     anfragen lieferantenbestellungen einkaufsrechnungen taxnumber co_ustid duns menustyle
 
1075     template_format copies);
 
1077   $main::lxdebug->leave_sub();
 
1083   $main::lxdebug->enter_sub();
 
1085   my ($self, $msg) = @_;
 
1087   if ($ENV{HTTP_USER_AGENT}) {
 
1088     print qq|Content-Type: text/html
 
1090 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
 
1092 <body bgcolor=ffffff>
 
1094 <h2><font color=red>Error!</font></h2>
 
1099   die "Error: $msg\n";
 
1101   $main::lxdebug->leave_sub();