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 #=====================================================================
 
  41   $main::lxdebug->enter_sub();
 
  43   my ($type, $memfile, $login) = @_;
 
  47     &error("", "$memfile locked!") if (-f "${memfile}.LCK");
 
  49     open(MEMBER, "$memfile") or &error("", "$memfile : $!");
 
  60           # remove any trailing whitespace
 
  63           ($key, $value) = split(/=/, $_, 2);
 
  65           if (($key eq "stylesheet") && ($value eq "sql-ledger.css")) {
 
  66             $value = "lx-office-erp.css";
 
  69           $self->{$key} = $value;
 
  72         $self->{login} = $login;
 
  80   $main::lxdebug->leave_sub();
 
  85   $main::lxdebug->enter_sub();
 
  90   # scan the locale directory and read in the LANGUAGE files
 
  91   opendir(DIR, "locale");
 
  93   my @dir = grep(!/(^\.\.?$|\..*)/, readdir(DIR));
 
  95   foreach my $dir (@dir) {
 
  96     next unless open(FH, "locale/$dir/LANGUAGE");
 
 100     $cc{$dir} = "@language";
 
 105   $main::lxdebug->leave_sub();
 
 111   $main::lxdebug->enter_sub();
 
 113   my ($self, $form, $userspath) = @_;
 
 117   if ($self->{login}) {
 
 119     if ($self->{password}) {
 
 120       if ($form->{hashed_password}) {
 
 121         $form->{password} = $form->{hashed_password};
 
 123         $form->{password} = crypt($form->{password},
 
 124                                   substr($self->{login}, 0, 2));
 
 126       if ($self->{password} ne $form->{password}) {
 
 127         $main::lxdebug->leave_sub();
 
 132     unless (-e "$userspath/$self->{login}.conf") {
 
 133       $self->create_config("$userspath/$self->{login}.conf");
 
 136     do "$userspath/$self->{login}.conf";
 
 137     $myconfig{dbpasswd} = unpack('u', $myconfig{dbpasswd});
 
 139     # check if database is down
 
 141       DBI->connect($myconfig{dbconnect}, $myconfig{dbuser},
 
 143       or $self->error(DBI::errstr);
 
 145     # we got a connection, check the version
 
 146     my $query = qq|SELECT version FROM defaults|;
 
 147     my $sth   = $dbh->prepare($query);
 
 148     $sth->execute || $form->dberror($query);
 
 150     my ($dbversion) = $sth->fetchrow_array;
 
 153     # add login to employee table if it does not exist
 
 154     # no error check for employee table, ignore if it does not exist
 
 155     $query = qq|SELECT id FROM employee WHERE login = ?|;
 
 156     my ($login) = selectrow_query($form, $dbh, $query, $self->{login});
 
 159       $query = qq|INSERT INTO employee (login, name, workphone, role)| .
 
 160                qq|VALUES (?, ?, ?, ?)|;
 
 161       my @values = ($self->{login}, $myconfig{name}, $myconfig{tel}, "user");
 
 162       do_query($form, $dbh, $query, @values);
 
 165     $self->create_schema_info_table($form, $dbh);
 
 172       parse_dbupdate_controls($form, $myconfig{"dbdriver"});
 
 174     map({ $form->{$_} = $myconfig{$_} }
 
 175         qw(dbname dbhost dbport dbdriver dbuser dbpasswd dbconnect));
 
 177     if (update_available($myconfig{"dbdriver"}, $dbversion) ||
 
 178         update2_available($form, $controls)) {
 
 180       $form->{"stylesheet"} = "lx-office-erp.css";
 
 181       $form->{"title"} = $main::locale->text("Dataset upgrade");
 
 183       print($form->parse_html_template("dbupgrade/header"));
 
 185       $form->{dbupdate} = "db$myconfig{dbname}";
 
 186       $form->{ $form->{dbupdate} } = 1;
 
 188       if ($form->{"show_dbupdate_warning"}) {
 
 189         print($form->parse_html_template("dbupgrade/warning"));
 
 194       open(FH, ">$userspath/nologin") or die("$!");
 
 196       # required for Oracle
 
 197       $form->{dbdefault} = $sid;
 
 199       # ignore HUP, QUIT in case the webserver times out
 
 200       $SIG{HUP}  = 'IGNORE';
 
 201       $SIG{QUIT} = 'IGNORE';
 
 203       $self->dbupdate($form);
 
 204       $self->dbupdate2($form, $controls);
 
 207       unlink("$userspath/nologin");
 
 210         $self->{"menustyle"} eq "v3" ? "menuv3.pl" :
 
 211         $self->{"menustyle"} eq "neu" ? "menunew.pl" :
 
 214       print($form->parse_html_template("dbupgrade/footer",
 
 215                                        { "menufile" => $menufile }));
 
 222   $main::lxdebug->leave_sub();
 
 228   $main::lxdebug->enter_sub();
 
 230   my ($form, $db) = @_;
 
 233         'Pg' => { 'yy-mm-dd'   => 'set DateStyle to \'ISO\'',
 
 234                   'yyyy-mm-dd' => 'set DateStyle to \'ISO\'',
 
 235                   'mm/dd/yy'   => 'set DateStyle to \'SQL, US\'',
 
 236                   'mm-dd-yy'   => 'set DateStyle to \'POSTGRES, US\'',
 
 237                   'dd/mm/yy'   => 'set DateStyle to \'SQL, EUROPEAN\'',
 
 238                   'dd-mm-yy'   => 'set DateStyle to \'POSTGRES, EUROPEAN\'',
 
 239                   'dd.mm.yy'   => 'set DateStyle to \'GERMAN\''
 
 242           'yy-mm-dd'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'YY-MM-DD\'',
 
 243           'yyyy-mm-dd' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'YYYY-MM-DD\'',
 
 244           'mm/dd/yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'MM/DD/YY\'',
 
 245           'mm-dd-yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'MM-DD-YY\'',
 
 246           'dd/mm/yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD/MM/YY\'',
 
 247           'dd-mm-yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD-MM-YY\'',
 
 248           'dd.mm.yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD.MM.YY\'',
 
 251   $form->{dboptions} = $dboptions{ $form->{dbdriver} }{ $form->{dateformat} };
 
 253   if ($form->{dbdriver} eq 'Pg') {
 
 254     $form->{dbconnect} = "dbi:Pg:dbname=$db";
 
 257   if ($form->{dbdriver} eq 'Oracle') {
 
 258     $form->{dbconnect} = "dbi:Oracle:sid=$form->{sid}";
 
 261   if ($form->{dbhost}) {
 
 262     $form->{dbconnect} .= ";host=$form->{dbhost}";
 
 264   if ($form->{dbport}) {
 
 265     $form->{dbconnect} .= ";port=$form->{dbport}";
 
 268   $main::lxdebug->leave_sub();
 
 272   $main::lxdebug->enter_sub();
 
 274   my @drivers = DBI->available_drivers();
 
 276   $main::lxdebug->leave_sub();
 
 278   return (grep { /(Pg|Oracle)/ } @drivers);
 
 282   $main::lxdebug->enter_sub();
 
 284   my ($self, $form) = @_;
 
 289   $form->{dbdefault} = $form->{dbuser} unless $form->{dbdefault};
 
 290   $form->{sid} = $form->{dbdefault};
 
 291   &dbconnect_vars($form, $form->{dbdefault});
 
 294     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 297   if ($form->{dbdriver} eq 'Pg') {
 
 299       qq|SELECT datname FROM pg_database | .
 
 300       qq|WHERE NOT datname IN ('template0', 'template1')|;
 
 301     $sth = $dbh->prepare($query);
 
 302     $sth->execute() || $form->dberror($query);
 
 304     while (my ($db) = $sth->fetchrow_array) {
 
 306       if ($form->{only_acc_db}) {
 
 308         next if ($db =~ /^template/);
 
 310         &dbconnect_vars($form, $db);
 
 312           DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 316           qq|SELECT tablename FROM pg_tables | .
 
 317           qq|WHERE (tablename = 'defaults') AND (tableowner = ?)|;
 
 318         my $sth = $dbh->prepare($query);
 
 319         $sth->execute($form->{dbuser}) ||
 
 320           $form->dberror($query . " ($form->{dbuser})");
 
 322         if ($sth->fetchrow_array) {
 
 323           push(@dbsources, $db);
 
 329       push(@dbsources, $db);
 
 333   if ($form->{dbdriver} eq 'Oracle') {
 
 334     if ($form->{only_acc_db}) {
 
 336         qq|SELECT owner FROM dba_objects | .
 
 337         qq|WHERE object_name = 'DEFAULTS' AND object_type = 'TABLE'|;
 
 339       $query = qq|SELECT username FROM dba_users|;
 
 342     $sth = $dbh->prepare($query);
 
 343     $sth->execute || $form->dberror($query);
 
 345     while (my ($db) = $sth->fetchrow_array) {
 
 346       push(@dbsources, $db);
 
 353   $main::lxdebug->leave_sub();
 
 359   $main::lxdebug->enter_sub();
 
 361   my ($self, $form) = @_;
 
 363   $form->{sid} = $form->{dbdefault};
 
 364   &dbconnect_vars($form, $form->{dbdefault});
 
 366     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 368   $form->{db} =~ s/\"//g;
 
 370     'Pg'     => qq|CREATE DATABASE "$form->{db}"|,
 
 372     qq|CREATE USER "$form->{db}" DEFAULT TABLESPACE USERS | .
 
 373     qq|TEMPORARY TABLESPACE TEMP IDENTIFIED BY "$form->{db}"|
 
 380   push(@{$dboptions{"Pg"}}, "ENCODING = " . $dbh->quote($form->{"encoding"}))
 
 381     if ($form->{"encoding"});
 
 382   if ($form->{"dbdefault"}) {
 
 383     my $dbdefault = $form->{"dbdefault"};
 
 384     $dbdefault =~ s/[^a-zA-Z0-9_\-]//g;
 
 385     push(@{$dboptions{"Pg"}}, "TEMPLATE = $dbdefault");
 
 388   my $query = $dbcreate{$form->{dbdriver}};
 
 389   $query .= " WITH " . join(" ", @{$dboptions{"Pg"}}) if (@{$dboptions{"Pg"}});
 
 391   do_query($form, $dbh, $query);
 
 393   if ($form->{dbdriver} eq 'Oracle') {
 
 394     $query = qq|GRANT CONNECT, RESOURCE TO "$form->{db}"|;
 
 395     do_query($form, $dbh, $query);
 
 399   # setup variables for the new database
 
 400   if ($form->{dbdriver} eq 'Oracle') {
 
 401     $form->{dbuser}   = $form->{db};
 
 402     $form->{dbpasswd} = $form->{db};
 
 405   &dbconnect_vars($form, $form->{db});
 
 407   $dbh = DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 411   my $filename = qq|sql/lx-office.sql|;
 
 412   $self->process_query($form, $dbh, $filename);
 
 414   # load chart of accounts
 
 415   $filename = qq|sql/$form->{chart}-chart.sql|;
 
 416   $self->process_query($form, $dbh, $filename);
 
 418   $query = "UPDATE defaults SET coa = ?";
 
 419   do_query($form, $dbh, $query, $form->{chart});
 
 423   $main::lxdebug->leave_sub();
 
 426 # Process a Perl script which updates the database.
 
 427 # If the script returns 1 then the update was successful.
 
 428 # Return code "2" means "needs more interaction; remove
 
 429 # users/nologin and exit".
 
 430 # All other return codes are fatal errors.
 
 431 sub process_perl_script {
 
 432   $main::lxdebug->enter_sub();
 
 434   my ($self, $form, $dbh, $filename, $version_or_control) = @_;
 
 436   open(FH, "$filename") or $form->error("$filename : $!\n");
 
 437   my $contents = join("", <FH>);
 
 442   my %dbup_myconfig = ();
 
 443   map({ $dbup_myconfig{$_} = $form->{$_}; }
 
 444       qw(dbname dbuser dbpasswd dbhost dbport dbconnect));
 
 446   my $nls_file = $filename;
 
 447   $nls_file =~ s|.*/||;
 
 448   $nls_file =~ s|.pl$||;
 
 449   my $dbup_locale = Locale->new($main::language, $nls_file);
 
 451   my $result = eval($contents);
 
 458   if (!defined($result)) {
 
 459     print($form->parse_html_template("dbupgrade/error",
 
 460                                      { "file" => $filename,
 
 463   } elsif (1 != $result) {
 
 464     unlink("users/nologin") if (2 == $result);
 
 468   if (ref($version_or_control) eq "HASH") {
 
 469     $dbh->do("INSERT INTO schema_info (tag, login) VALUES (" .
 
 470              $dbh->quote($version_or_control->{"tag"}) . ", " .
 
 471              $dbh->quote($form->{"login"}) . ")");
 
 472   } elsif ($version_or_control) {
 
 473     $dbh->do("UPDATE defaults SET version = " .
 
 474              $dbh->quote($version_or_control));
 
 478   $main::lxdebug->leave_sub();
 
 482   $main::lxdebug->enter_sub();
 
 484   my ($self, $form, $dbh, $filename, $version_or_control) = @_;
 
 486   open(FH, "$filename") or $form->error("$filename : $!\n");
 
 495     # Remove DOS and Unix style line endings.
 
 501     for (my $i = 0; $i < length($_); $i++) {
 
 502       my $char = substr($_, $i, 1);
 
 504       # Are we inside a string?
 
 506         if ($char eq $quote_chars[-1]) {
 
 512         if (($char eq "'") || ($char eq "\"")) {
 
 513           push(@quote_chars, $char);
 
 515         } elsif ($char eq ";") {
 
 517           # Query is complete. Send it.
 
 519           $sth = $dbh->prepare($query);
 
 520           if (!$sth->execute()) {
 
 521             my $errstr = $dbh->errstr;
 
 524             $form->dberror("The database update/creation did not succeed. " .
 
 525                            "The file ${filename} containing the following " .
 
 526                            "query failed:<br>${query}<br>" .
 
 527                            "The error message was: ${errstr}<br>" .
 
 528                            "All changes in that file have been reverted.");
 
 541   if (ref($version_or_control) eq "HASH") {
 
 542     $dbh->do("INSERT INTO schema_info (tag, login) VALUES (" .
 
 543              $dbh->quote($version_or_control->{"tag"}) . ", " .
 
 544              $dbh->quote($form->{"login"}) . ")");
 
 545   } elsif ($version_or_control) {
 
 546     $dbh->do("UPDATE defaults SET version = " .
 
 547              $dbh->quote($version_or_control));
 
 553   $main::lxdebug->leave_sub();
 
 557   $main::lxdebug->enter_sub();
 
 559   my ($self, $form) = @_;
 
 560   $form->{db} =~ s/\"//g;
 
 561   my %dbdelete = ('Pg'     => qq|DROP DATABASE "$form->{db}"|,
 
 562                   'Oracle' => qq|DROP USER "$form->{db}" CASCADE|);
 
 564   $form->{sid} = $form->{dbdefault};
 
 565   &dbconnect_vars($form, $form->{dbdefault});
 
 567     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 569   my $query = $dbdelete{$form->{dbdriver}};
 
 570   do_query($form, $dbh, $query);
 
 574   $main::lxdebug->leave_sub();
 
 577 sub dbsources_unused {
 
 578   $main::lxdebug->enter_sub();
 
 580   my ($self, $form, $memfile) = @_;
 
 585   $form->error('File locked!') if (-f "${memfile}.LCK");
 
 588   open(FH, "$memfile") or $form->error("$memfile : $!");
 
 592       my ($null, $item) = split(/=/);
 
 599   $form->{only_acc_db} = 1;
 
 600   my @db = &dbsources("", $form);
 
 602   push @dbexcl, $form->{dbdefault};
 
 604   foreach $item (@db) {
 
 605     unless (grep /$item$/, @dbexcl) {
 
 606       push @dbsources, $item;
 
 610   $main::lxdebug->leave_sub();
 
 616   $main::lxdebug->enter_sub();
 
 618   my ($self, $form) = @_;
 
 623   $form->{sid} = $form->{dbdefault};
 
 624   &dbconnect_vars($form, $form->{dbdefault});
 
 627     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 630   if ($form->{dbdriver} eq 'Pg') {
 
 633       qq|SELECT d.datname FROM pg_database d, pg_user u | .
 
 634       qq|WHERE d.datdba = u.usesysid AND u.usename = ?|;
 
 635     my $sth = prepare_execute_query($form, $dbh, $query, $form->{dbuser});
 
 637     while (my ($db) = $sth->fetchrow_array) {
 
 639       next if ($db =~ /^template/);
 
 641       &dbconnect_vars($form, $db);
 
 644         DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 648         qq|SELECT tablename FROM pg_tables | .
 
 649         qq|WHERE tablename = 'defaults'|;
 
 650       my $sth2 = prepare_execute_query($form, $dbh, $query);
 
 652       if ($sth2->fetchrow_array) {
 
 653         $query = qq|SELECT version FROM defaults|;
 
 654         my ($version) = selectrow_query($form, $dbh2, $query);
 
 655         $dbsources{$db} = $version;
 
 663   if ($form->{dbdriver} eq 'Oracle') {
 
 665       qq|SELECT owner FROM dba_objects |.
 
 666       qq|WHERE object_name = 'DEFAULTS' AND 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();
 
 701   $main::lxdebug->enter_sub(2);
 
 703   my (@v, $version, $i);
 
 705   @v = split(/\./, $_[0]);
 
 706   while (scalar(@v) < 4) {
 
 710   for ($i = 0; $i < 4; $i++) {
 
 715   $main::lxdebug->leave_sub(2);
 
 719 sub cmp_script_version {
 
 720   my ($a_from, $a_to, $b_from, $b_to);
 
 721   my ($i, $res_a, $res_b);
 
 722   my ($my_a, $my_b) = ($a, $b);
 
 724   $my_a =~ s/.*-upgrade-//;
 
 726   $my_b =~ s/.*-upgrade-//;
 
 728   ($my_a_from, $my_a_to) = split(/-/, $my_a);
 
 729   ($my_b_from, $my_b_to) = split(/-/, $my_b);
 
 731   $res_a = calc_version($my_a_from);
 
 732   $res_b = calc_version($my_b_from);
 
 734   if ($res_a == $res_b) {
 
 735     $res_a = calc_version($my_a_to);
 
 736     $res_b = calc_version($my_b_to);
 
 739   return $res_a <=> $res_b;
 
 742 sub update_available {
 
 743   my ($dbdriver, $cur_version) = @_;
 
 745   opendir(SQLDIR, "sql/${dbdriver}-upgrade")
 
 746     or &error("", "sql/${dbdriver}-upgrade: $!");
 
 748     grep(/$form->{dbdriver}-upgrade-\Q$cur_version\E.*\.(sql|pl)$/,
 
 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       qq|CREATE TABLE schema_info (| .
 
 766       qq|  itime timestamp DEFAULT now(), | .
 
 767       qq|  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")
 
 789       or &error("", "sql/" . $form->{dbdriver} . "-upgrade : $!");
 
 791       sort(cmp_script_version
 
 792            grep(/$form->{dbdriver}-upgrade-.*?\.(sql|pl)$/,
 
 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 ($version) = selectrow_query($form, $dbh, $query);
 
 813     next unless $version;
 
 815     $version = calc_version($version);
 
 817     foreach my $upgradescript (@upgradescripts) {
 
 818       my $a = $upgradescript;
 
 819       $a =~ s/^$form->{dbdriver}-upgrade-|\.(sql|pl)$//g;
 
 822       my ($mindb, $maxdb) = split /-/, $a;
 
 823       my $str_maxdb = $maxdb;
 
 824       $mindb = calc_version($mindb);
 
 825       $maxdb = calc_version($maxdb);
 
 827       next if ($version >= $maxdb);
 
 829       # if there is no upgrade script exit
 
 830       last if ($version < $mindb);
 
 833       $main::lxdebug->message(DEBUG2, "Applying Update $upgradescript");
 
 834       if ($file_type eq "sql") {
 
 835         $self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} .
 
 836                              "-upgrade/$upgradescript", $str_maxdb);
 
 838         $self->process_perl_script($form, $dbh, "sql/" . $form->{"dbdriver"} .
 
 839                                    "-upgrade/$upgradescript", $str_maxdb);
 
 851   $main::lxdebug->leave_sub();
 
 857   $main::lxdebug->enter_sub();
 
 859   my ($self, $form, $controls) = @_;
 
 861   $form->{sid} = $form->{dbdefault};
 
 863   my @upgradescripts = ();
 
 864   my ($query, $sth, $tag);
 
 867   @upgradescripts = sort_dbupdate_controls($controls);
 
 869   foreach my $db (split / /, $form->{dbupdate}) {
 
 871     next unless $form->{$db};
 
 873     # strip db from dataset
 
 875     &dbconnect_vars($form, $db);
 
 878       DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
 
 881     map({ $_->{"applied"} = 0; } @upgradescripts);
 
 883     $query = qq|SELECT tag FROM schema_info|;
 
 884     $sth = $dbh->prepare($query);
 
 885     $sth->execute() || $form->dberror($query);
 
 886     while (($tag) = $sth->fetchrow_array()) {
 
 887       $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
 
 892     foreach (@upgradescripts) {
 
 893       if (!$_->{"applied"}) {
 
 899     next if ($all_applied);
 
 901     foreach my $control (@upgradescripts) {
 
 902       next if ($control->{"applied"});
 
 904       $control->{"file"} =~ /\.(sql|pl)$/;
 
 908       $main::lxdebug->message(DEBUG2, "Applying Update $control->{file}");
 
 909       print($form->parse_html_template("dbupgrade/upgrade_message2",
 
 912       if ($file_type eq "sql") {
 
 913         $self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} .
 
 914                              "-upgrade2/$control->{file}", $control);
 
 916         $self->process_perl_script($form, $dbh, "sql/" . $form->{"dbdriver"} .
 
 917                                    "-upgrade2/$control->{file}", $control);
 
 926   $main::lxdebug->leave_sub();
 
 931 sub update2_available {
 
 932   $main::lxdebug->enter_sub();
 
 934   my ($form, $controls) = @_;
 
 936   map({ $_->{"applied"} = 0; } values(%{$controls}));
 
 938   dbconnect_vars($form, $form->{"dbname"});
 
 941     DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) ||
 
 944   my ($query, $tag, $sth);
 
 946   $query = qq|SELECT tag FROM schema_info|;
 
 947   $sth = $dbh->prepare($query);
 
 948   $sth->execute() || $form->dberror($query);
 
 949   while (($tag) = $sth->fetchrow_array()) {
 
 950     $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
 
 955   map({ $main::lxdebug->leave_sub() and return 1 if (!$_->{"applied"}) }
 
 956       values(%{$controls}));
 
 958   $main::lxdebug->leave_sub();
 
 963   $main::lxdebug->enter_sub();
 
 965   my ($self, $filename) = @_;
 
 967   @config = &config_vars;
 
 969   open(CONF, ">$filename") or $self->error("$filename : $!");
 
 971   # create the config file
 
 972   print CONF qq|# configuration file for $self->{login}
 
 977   foreach $key (sort @config) {
 
 978     $self->{$key} =~ s/\'/\\\'/g;
 
 979     print CONF qq|  $key => '$self->{$key}',\n|;
 
 982   print CONF qq|);\n\n|;
 
 986   $main::lxdebug->leave_sub();
 
 990   $main::lxdebug->enter_sub();
 
 992   my ($self, $memberfile, $userspath) = @_;
 
 996   # format dbconnect and dboptions string
 
 997   &dbconnect_vars($self, $self->{dbname});
 
 999   $self->error('File locked!') if (-f "${memberfile}.LCK");
 
1000   open(FH, ">${memberfile}.LCK") or $self->error("${memberfile}.LCK : $!");
 
1003   open(CONF, "+<$memberfile") or $self->error("$memberfile : $!");
 
1010   while ($line = shift @config) {
 
1011     if ($line =~ /^\[$self->{login}\]/) {
 
1018   # remove everything up to next login or EOF
 
1019   while ($line = shift @config) {
 
1020     last if ($line =~ /^\[/);
 
1023   # this one is either the next login or EOF
 
1026   while ($line = shift @config) {
 
1030   print CONF qq|[$self->{login}]\n|;
 
1032   if ((($self->{dbpasswd} ne $self->{old_dbpasswd}) || $newmember)
 
1034     $self->{dbpasswd} = pack 'u', $self->{dbpasswd};
 
1035     chop $self->{dbpasswd};
 
1037   if (defined($self->{new_password})) {
 
1038     if ($self->{new_password} ne $self->{old_password}) {
 
1039       $self->{password} = crypt $self->{new_password},
 
1040         substr($self->{login}, 0, 2)
 
1041         if $self->{new_password};
 
1044     if ($self->{password} ne $self->{old_password}) {
 
1045       $self->{password} = crypt $self->{password}, substr($self->{login}, 0, 2)
 
1046         if $self->{password};
 
1050   if ($self->{'root login'}) {
 
1051     @config = ("password");
 
1053     @config = &config_vars;
 
1056   # replace \r\n with \n
 
1057   map { $self->{$_} =~ s/\r\n/\\n/g } qw(address signature);
 
1058   foreach $key (sort @config) {
 
1059     print CONF qq|$key=$self->{$key}\n|;
 
1064   unlink "${memberfile}.LCK";
 
1067   $self->create_config("$userspath/$self->{login}.conf")
 
1068     unless $self->{'root login'};
 
1070   $main::lxdebug->leave_sub();
 
1074   $main::lxdebug->enter_sub();
 
1076   my @conf = qw(acs address admin businessnumber charset company countrycode
 
1077     currency dateformat dbconnect dbdriver dbhost dbport dboptions
 
1078     dbname dbuser dbpasswd email fax name numberformat password
 
1079     printer role sid signature stylesheet tel templates vclimit angebote
 
1080     bestellungen rechnungen anfragen lieferantenbestellungen einkaufsrechnungen
 
1081     taxnumber co_ustid duns menustyle template_format default_media
 
1082     default_printer_id copies show_form_details);
 
1084   $main::lxdebug->leave_sub();
 
1090   $main::lxdebug->enter_sub();
 
1092   my ($self, $msg) = @_;
 
1094   if ($ENV{HTTP_USER_AGENT}) {
 
1095     print qq|Content-Type: text/html
 
1097 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
 
1099 <body bgcolor=ffffff>
 
1101 <h2><font color=red>Error!</font></h2>
 
1106   die "Error: $msg\n";
 
1108   $main::lxdebug->leave_sub();